Пример #1
0
 function printHello()
 {
     MyClass::printHello();
     print "MyClass2::printHello() " . $this->Hello;
     print "MyClass2::printHello() " . $this->Bar;
     print "MyClass2::printHello() " . $this->Foo;
 }
Пример #2
0
 function printHello()
 {
     MyClass::printHello();
     print "MyClass2::printHello() " . $this->public;
     print "MyClass2::printHello() " . $this->protected;
     print "MyClass2::printHello() " . $this->protected2;
     /* Will result in a Fatal Error: */
     //print "MyClass2::printHello() " . $this->private; /* Fatal Error */
 }
Пример #3
0
 public function printHello()
 {
     MyClass::printHello();
     /* Should print */
     print "MyClass2::printHello() " . $this->Hello;
     /* Shouldn't print out anything */
     print "MyClass2::printHello() " . $this->Bar;
     /* Shouldn't print (not declared)*/
     print "MyClass2::printHello() " . $this->Foo;
     /* Should print */
 }
Пример #4
0
    private $private = 'Private';
    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}
$obj = new MyClass();
echo $obj->public;
// Works
echo $obj->protected;
// Fatal Error
echo $obj->private;
// Fatal Error
$obj->printHello();
// Shows Public, Protected and Private
/**
* Define MyClass2
*/
class MyClass2 extends MyClass
{
    // We can redeclare the public and protected method, but not private
    protected $protected = 'Protected2';
    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}