05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 6-2. Object introspection functions (continued)<br />

$children[] = $class;<br />

}<br />

}<br />

return $children;<br />

}<br />

// display information on an object<br />

function print_object_info($object) {<br />

$class = get_class($object);<br />

echo 'Class';<br />

echo "$class";<br />

echo 'Inheritance';<br />

echo 'Parents';<br />

$lineage = get_lineage($object);<br />

array_pop($lineage);<br />

echo count($lineage) ? ('' . join(' -&gt; ', $lineage) . '')<br />

: 'None';<br />

echo 'Children';<br />

$children = get_child_classes($object);<br />

echo '' . (count($children) ? join(', ', $children)<br />

: 'None') . '';<br />

echo 'Methods';<br />

$methods = get_class_methods($class);<br />

$object_methods = get_methods($object);<br />

if(!count($methods)) {<br />

echo "None";<br />

}<br />

else {<br />

echo 'Inherited methods are in italics.';<br />

foreach($methods as $method) {<br />

echo in_array($method, $object_methods) ? "$method( );"<br />

: "$method( );";<br />

}<br />

}<br />

echo 'Properties';<br />

$properties = get_class_vars($class);<br />

if(!count($properties)) {<br />

echo "None";<br />

}<br />

else {<br />

foreach(array_keys($properties) as $property) {<br />

echo "\$$property = " . $object->$property . '';<br />

}<br />

}<br />

echo '';<br />

}<br />

152 | Chapter 6: Objects<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!