Re: Print extended/parent classes
| From: | Jochem Maas | Date: | Wed, 01 Feb 2006 14:06:47 +0000 |
| Subject: | Re: Print extended/parent classes | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229623@lists.php.net to get a copy of this message | ||
David Grant wrote:
Mathijs, Mathijs wrote:***object***I have the following situation : <?php class A { public $var1; } class B extends A { public $var2; } ?> Now I want to print this object
***class*** (class and object are not interchangable concepts - yet they are closely related :-) you printed $obj which is an instance of B, which happens to be a subclass of A. if you are interested to find out which classes an objects is defined by try something like: class A {} class B extends A {} class C extends B {} $c = "C"; $classes = array($c); while($c = get_parent_class($c)) $classes[] = $c; print_r($classes);<?php $obj = new B; print_r($obj); ?> Does anybody know how I can print class A also ?
The above prints out:
B Object
(
[var2] =>
[var1] =>
)
Is this not what you expected? You can't print out *just* the
properties of A. If this isn't what you want, you shouldn't be extending A.
David