note 116200 deleted from classobj.examples by salathe

From: Date: Fri, 21 Nov 2014 15:00:14 +0000
Subject: note 116200 deleted from classobj.examples by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200995@lists.php.net to get a copy of this message
Note Submitter: master at speed365 dot co dot kr ---- <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>

« previous php.notes (#200995) next »