Esempio n. 1
0
    function Vegetable($edible, $color = "green")
    {
        $this->edible = $edible;
        $this->color = $color;
        $this->blarg = $this->foo();
    }
    function is_edible()
    {
        return $this->edible;
    }
    function what_color()
    {
        return $this->color . $this->foo();
    }
    private function foo()
    {
        return 'foo';
    }
    function blahh()
    {
        echo self::$edible;
    }
}
$veggie = new Vegetable(true, "blue");
echo "public var edible: [" . $veggie->edible . "]\n";
echo "public var color: [" . $veggie->color . "]\n";
echo "public method: [" . $veggie->is_edible() . "]\n";
echo "public method calling private method: [" . $veggie->what_color() . "]\n";
// echo "private method: [".$veggie->foo()."]\n";
echo "private method: [" . $veggie->blarg . "]\n";
echo "class vars: [" . $veggie->blahh() . "]\n";
Esempio n. 2
0
    global ${$obj};
    if (is_subclass_of(${$obj}, $class)) {
        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";
    }
}
// instantiate 2 objects
$veggie = new Vegetable(true, "blue");
$leafy = new Spinach();
// 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";
// 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");
#print "brownly goes the deep chime: " . Vegetable::color . "\n";
Vegetable::staticable("a very special argument");
print "class vars for Vegetable: " . get_class_vars(get_class($veggie));
?>
</pre>