David Grant wrote:
Mathijs,
Mathijs wrote:
I have the following situation :
<?php
class A {
public $var1;
}
class B extends A {
public $var2;
}
?>
Now I want to print this object
***object***
<?php
$obj = new B;
print_r($obj);
?>
Does anybody know how I can print class A also ?
***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);
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php