本文整理汇总了PHP中B::myFunction方法的典型用法代码示例。如果您正苦于以下问题:PHP B::myFunction方法的具体用法?PHP B::myFunction怎么用?PHP B::myFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类B
的用法示例。
在下文中一共展示了B::myFunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: myFunction
// Declaration of a protected property and its initialization
private $c = "private \n";
// Declaration of a private property and its initialization
function myFunction()
{
echo $this->c;
// Accessing the private property inside the class
}
}
class B extends A
{
function myFunction()
{
echo $this->b;
// Accessing protected property of the parent class A
echo $this->c;
// Fatal error, attempt to access the private property of the parent class A
}
}
$obj1 = new A();
$obj2 = new B();
echo $obj1->a;
// Accessing of a public property is possible everywhere throughout the code
echo $obj1->b;
// Fatal error, attempt to access the protected property of the class A
echo $obj1->c;
// Fatal error, attempt to access the private property of the class A
$obj1->myFunction();
// Accessing the private member through the object of the class A
$obj2->myFunction();
// Accessing the protected member through the object of the class B