示例#1
0
    }
    public function setProperty($newval)
    {
        $this->prop1 = $newval;
    }
    protected function getProperty()
    {
        return $this->prop1 . "<br />";
    }
}
class MyOtherClass extends MyClass
{
    public function __construct()
    {
        parent::__construct();
        echo "A new constructor in " . __CLASS__ . ".<br />";
    }
    public function newMethod()
    {
        echo "From a new method in " . __CLASS__ . ".<br />";
    }
    public function callProtected()
    {
        return $this->getProperty();
    }
}
// Create a new object
$newobj = new MyOtherClass();
// Call the protected method from within a public method
echo $newobj->callProtected();