How to print object name in php?
So I got this source code Show
The dump returns several objects like this
I need to extract the object names as string like this:
Something like (PHP 4, PHP 5, PHP 7, PHP 8) get_class — Returns the name of the class of an object Descriptionget_class(object Parametersobject The tested object. This parameter may be omitted when inside a class.
Return Values Returns the name of the class of which If If the Errors/Exceptions If get_class() is called
with anything other than an object, TypeError is raised. Prior to PHP 8.0.0, an If get_class() is called with no arguments from outside a class, Error is raised. Prior to PHP 8.0.0, an Changelog
ExamplesExample #1 Using get_class()
The above example will output: Its name is foo My name is foo Example #2 Using get_class() in superclass
foo extends bar { The above example will output: string(3) "foo" string(3) "bar" Example #3 Using get_class() with namespaced classes
Baz { The above example will output: See Also
jjanak at webperfection dot net ¶ 8 years ago
Dispatcher {} dave at shax dot com ¶ 8 years ago
mail dot temc at gmail dot com ¶ 10 years ago
Bar extends Foo {
ovidiu.bute [at] gmail.com ¶ 12 years ago
emmanuel dot antico at gmail dot com ¶ 9 years ago
macnimble at gmail dot com ¶ 10 years ago
Nanhe Kumar ¶ 8 years ago
Anonymous ¶ 14 years ago
Edward ¶ 14 years ago
RQuadling at GMail dot com ¶ 7 years ago
Baz davidsch ¶ 1 year ago
getInstance(): ACFBlock { Anonymous ¶ 8 years ago
foo extends \system\libs\controller { Hayley Watson ¶ 5 years ago
dense ¶ 5 years ago
var23rav at gmail dot com ¶ 8 years ago
Aaron ¶ 12 years ago
ozana at omdesign dot cz ¶ 10 years ago
Foo {
Michael Richey ¶ 10 years ago
Exception("Unknown backtrace method type");
me at nwhiting dot com ¶ 11 years ago
function get_class_name($object = null) dodgie74 at NOSPAM dot yahoo dot NOSPAM dot co dot uk ¶ 15 years ago
classDisplayName() bramus at bram dot us ¶ 15 years ago
yicheng zero-four at gmail dot com ¶ 15 years ago
luke at liveoakinteractive dot com ¶ 15 years ago
retrieve_class() { benjaminhill at gmail dot com ¶ 16 years ago
refrozen dot com ¶ 17 years ago
andregs at NOSPAM dot gmail dot NOSPAM dot com ¶ 14 years ago
Child extends Singleton Frederik Krautwald ¶ 15 years ago
__construct() {} mightye at gmail dot com ¶ 15 years ago
__construct(){} janci ¶ 15 years ago
getInstance()
MagicalTux at FF.ST ¶ 18 years ago
dave dot zap at gmail dot com ¶ 14 years ago
XyQrTw ¶ 5 years ago
MyClass {
danbettles at yahoo dot co dot uk ¶ 13 years ago
__construct() { Edward ¶ 14 years ago
Lanselot ¶ 13 years ago
kiril (AT) aternus networks ¶ 4 years ago
How do you print an object of an object in PHP?The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable. Parameters: This function accepts two parameters as shown in above syntax and described below. $variable: This parameter specifies the variable to be printed and is a mandatory parameter.
What is object in PHP with example?An Object is an individual instance of the data structure defined by a class. We define a class once and then make many objects that belong to it. Objects are also known as instances.
What is a stdClass object?The stdClass is the empty class in PHP which is used to cast other types to object. It is similar to Java or Python object. The stdClass is not the base class of the objects. If an object is converted to object, it is not modified.
How do you access the properties of an object in PHP?Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property .
|