i have a class that extends another.
when i iterate the current object i get all properties, even those from the superclass.
i only want to iterate through the current object. how could i do that?
foreach($this as $key => $value) {
echo $key . ': ' . $value;
}
Very interesting question.
I will highly recommend to read the examples here – http://dsl093-056-122.blt1.dsl.speakeasy.net/edu/oreilly/Oreilly_Web_Programming_bookshelf/webprog/php/ch06_05.htm they will give you greater insight about Introspection. The reference about those methods used is here – http://www.php.net/manual/en/ref.classobj.php
Here is the function with a test case. It will work only in PHP 5+ as it uses Reflection which was not available before that. You can read more about Reflection here – http://www.php.net/manual/en/class.reflectionclass.php