本文整理匯總了PHP中Bar::echoPublic方法的典型用法代碼示例。如果您正苦於以下問題:PHP Bar::echoPublic方法的具體用法?PHP Bar::echoPublic怎麽用?PHP Bar::echoPublic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Bar
的用法示例。
在下文中一共展示了Bar::echoPublic方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: echoPublic
public function echoPublic()
{
var_dump(__METHOD__, $this->protected);
$this->echoProtected();
}
public function echoPrivateDirectly()
{
var_dump(__METHOD__);
var_dump($this->private);
}
}
/*
__METHOD__ is known as a magic constant. In the usage here, this allows us to var_dump
the current method we're in, allowing us to see what's calling what in this script.
*/
$class = new Bar();
$class->echoPublic();
// External calls can only call public methods.
# $class->echoProtected(); // would not work here (due to protected scope), but will work inside the class.
$class->echoPrivateDirectly();
// This will fail as the Bar class doesn't have access to $this->private within Foo.
/*
Result:
string 'Bar::echoPublic' (length=15)
string 'Protected' (length=9)
string 'Foo::echoProtected' (length=18)
string 'Private' (length=7)
string 'Bar::echoPrivateDirectly' (length=24)
Notice: Undefined property: Bar::$private
null
*/