note 116200 added to classobj.examples
| From: | master at speed365 dot co dot kr | Date: | Fri, 21 Nov 2014 01:17:47 +0000 |
| Subject: | note 116200 added to classobj.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200970@lists.php.net to get a copy of this message | ||
<pre>
<?php
include "classes.inc";
// utility functions
// instantiate 2 objects
$veggie = new Vegetable(true, "blue");//$edible=true,$color=blue
$leafy = new Spinach();//$edible=true,$color=green
function print_vars($obj) // ë³ìì¶ë ¥
{
foreach (get_object_vars($obj) as $prop => $val) {
echo "\t$prop = $val\n";
}
}
function print_methods($obj) //ë´ì¥í¨ìì¶ë ¥
{
$arr = get_class_methods(get_class($obj));
foreach ($arr as $method) {
echo "\tfunction $method()\n";
}
}
function class_parentage($obj, $class) //
{
global $$obj;
if (is_subclass_of($GLOBALS[$obj], $class)) {//$GLOBALS[leafy],Spinach==>Spinach(),Spinach
echo "Object $obj belongs to class " . get_class($$obj);
echo " a subclass of $class\n";
} else {
echo "Object $obj does not belong to a subclass of $class\n";
}
}
// print out information about objects
echo "veggie: CLASS " . get_class($veggie) . "\n";
echo "leafy: CLASS " . get_class($leafy);
echo ", PARENT " . get_parent_class($leafy) . "\n";
echo "test:--".$leafy->cooked."--\n";
// show veggie properties
echo "\nveggie: Properties\n";
print_vars($veggie);
// and leafy methods
echo "\nleafy: Methods\n";
print_methods($leafy);
echo "\nParentage:\n";
class_parentage("leafy", "Spinach");
class_parentage("leafy", "Vegetable");
class_parentage("veggie", "Vegetable");
class_parentage("veggie", "Spinach");
?>
</pre>
----
Server IP: 72.52.91.14
Probable Submitter: 125.131.152.72
----
Manual Page -- http://php.net/manual/en/classobj.examples.php
Edit -- https://master.php.net/note/edit/116200
Del: integrated -- https://master.php.net/note/delete/116200/integrated
Del: useless -- https://master.php.net/note/delete/116200/useless
Del: bad code -- https://master.php.net/note/delete/116200/bad+code
Del: spam -- https://master.php.net/note/delete/116200/spam
Del: non-english -- https://master.php.net/note/delete/116200/non-english
Del: in docs -- https://master.php.net/note/delete/116200/in+docs
Del: other reasons-- https://master.php.net/note/delete/116200
Reject -- https://master.php.net/note/reject/116200
Search -- https://master.php.net/manage/user-notes.php