本文整理汇总了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
*/