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


PHP MyClass::WhoAmI方法代碼示例

本文整理匯總了PHP中MyClass::WhoAmI方法的典型用法代碼示例。如果您正苦於以下問題:PHP MyClass::WhoAmI方法的具體用法?PHP MyClass::WhoAmI怎麽用?PHP MyClass::WhoAmI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MyClass的用法示例。


在下文中一共展示了MyClass::WhoAmI方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: WhoAmI

    return __FUNCTION__;
}
class MyClass
{
    static function WhoAmI()
    {
        return __METHOD__;
    }
}
echo MYCONST . "<br/>";
//    App\Lib1\MYCONST
var_dump(MYCONST) . "<br/>";
//    string(16) "App\Lib1\MYCONST"
echo MyFunction() . "<br/>";
//   App\Lib1\MyFunction
var_dump(MyFunction()) . "<br/>";
//   string(19) "App\Lib1\MyFunction"
echo "<br/>" . MyClass::WhoAmI() . "<br/>";
//    App\Lib1\MyClass::WhoAmI
var_dump(MyClass::WhoAmI()) . "<br/>";
//    string(24) "App\Lib1\MyClass::WhoAmI"
?>

<?php 
//  myapp.php
header('Content-type: text/plain');
require_once 'lib1.php';
// calling lib1.php
echo \App\Lib1\MYCONST . "\n";
echo \App\Lib1\MyFunction() . "\n";
echo \App\Lib1\MyClass::WhoAmI() . "\n";
開發者ID:KB-WEB-DEVELOPMENT,項目名稱:Kami_Barut_PHP_projects,代碼行數:31,代碼來源:accessing+namespace+content+in++a+file.php

示例2: header

?>


<?php 
namespace App\Lib1;

require_once 'lib1.php';
// const, functions and classes here will be called
require_once 'lib2.php';
//  const, functions and classes here will not be called
header('Content-type: text/plain');
echo MYCONST . "\n";
//  App\Lib1\MYCONST
echo MyFunction() . "\n";
//  App\Lib1\MyFunction
echo MyClass::WhoAmI() . "\n";
//  App\Lib1\MyClass::WhoAmI
?>

<?php 
use App\Lib2;
require_once 'lib1.php';
require_once 'lib2.php';
header('Content-type: text/plain');
echo Lib2\MYCONST . "\n";
//  App\Lib1\MYCONST   ATTENTION !
echo Lib2\MyFunction() . "\n";
//  App\Lib2\MyFunction
echo Lib2\MyClass::WhoAmI() . "\n";
//  App\Lib2\MyClass::WhoAmI
?>
開發者ID:KB-WEB-DEVELOPMENT,項目名稱:Kami_Barut_PHP_projects,代碼行數:31,代碼來源:Accessing+data+from+various+namespaces.php

示例3: WhoAmI

class MyClass
{
    public function WhoAmI()
    {
        return __METHOD__;
    }
}
$c = __NAMESPACE__ . '\\MyClass';
$m = new $c();
echo $m->WhoAmI() . '<br/>';
// output: App\Lib1\MyClass::WhoAmI
var_dump($m->WhoAmI());
// output: string(24) "App\Lib1\MyClass::WhoAmI"
?>

<?php 
// namespace keyword
namespace App\Lib1;

class MyClass
{
    public function WhoAmI()
    {
        return __METHOD__;
    }
}
$m = new namespace\MyClass();
echo $m->WhoAmI() . '<br/>';
// output: App\Lib1\MyClass::WhoAmI
var_dump($m->WhoAmI());
// output: string(24) "App\Lib1\MyClass::WhoAmI"
開發者ID:KB-WEB-DEVELOPMENT,項目名稱:Kami_Barut_PHP_projects,代碼行數:31,代碼來源:namespace+constants+and+keywords.php


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