Re: Print extended/parent classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem,

Good point.  I thought he meant object given his example. :P

David

Jochem Maas wrote:
> 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
> 


-- 
David Grant
http://www.grant.org.uk/

http://pear.php.net/package/File_Ogg    0.2.1
http://pear.php.net/package/File_XSPF   0.1.0

WANTED: Junior PHP Developer in Bristol, UK

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux