當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Bar::echoPublic方法代碼示例

本文整理匯總了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
*/
開發者ID:Maelstromeous,項目名稱:learning-php,代碼行數:31,代碼來源:index.php


注:本文中的Bar::echoPublic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。