Esempio n. 1
0
<?php

## self не позволяет переопределить метод.
class Base
{
    public static function title()
    {
        echo __CLASS__;
    }
    public static function test()
    {
        self::title();
    }
}
class Child extends Base
{
    public static function title()
    {
        echo __CLASS__;
    }
}
Child::test();
// Base
{
    function test()
    {
        var_dump(get_class_vars("Tester"));
    }
    static function testStatic()
    {
        var_dump(get_class_vars("Tester"));
    }
}
echo "*** Testing get_class_vars() : testing visibility\n";
echo "\n-- From global context --\n";
var_dump(get_class_vars("Tester"));
echo "\n-- From inside an object instance --\n";
$instance = new Tester();
$instance->test();
echo "\n-- From  a static context --\n";
Tester::testStatic();
echo "\n-- From inside an  parent object instance --\n";
$parent = new Ancestor();
$parent->test();
echo "\n-- From a parents static context --\n";
Ancestor::testStatic();
echo "\n-- From inside a child object instance --\n";
$child = new Child();
$child->test();
echo "\n-- From a child's static context --\n";
Child::testStatic();
?>
===DONE===
<?php

class Base
{
    public function test()
    {
        $this->sayMyName();
    }
    private function sayMyName()
    {
        echo "My name is Base";
    }
}
class Child extends Base
{
    private function sayMyName()
    {
        echo "My name is Child";
    }
}
$ins = new Child();
$ins->test();