I have an unknown object in php page.
How can I print/echo it, so I can see what properties/values do it have?
What about functions? Is there any way to know what functions an object have?
To print the attributes of an object we can use “object. __dict__” and it return a dictionary of all names and attributes of object. After writing the above code (python print object attributes), once you will print “x.
To get all own properties of an object in JavaScript, you can use the Object. getOwnPropertyNames() method. This method returns an array containing all the names of the enumerable and non-enumerable own properties found directly on the object passed in as an argument.
values() Method: The Object. values() method is used to return an array of the object's own enumerable property values. The array can be looped using a for-loop to get all the values of the object.
<?php var_dump(obj) ?>
or
<?php print_r(obj) ?>
These are the same things you use for arrays too.
These will show protected and private properties of objects with PHP 5. Static class members will not be shown according to the manual.
If you want to know the member methods you can use get_class_methods():
$class_methods = get_class_methods('myclass'); // or $class_methods = get_class_methods(new myclass()); foreach ($class_methods as $method_name) { echo "$method_name<br/>"; }
Related stuff:
get_object_vars()
get_class_vars()
get_class() <-- for the name of the instance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With