PHP類和對象函數執行個體詳解_PHP教程

來源:互聯網
上載者:User
1. interface_exists、class_exists、method_exists和property_exists: 顧名思義,從以上幾個函數的命名便可以猜出幾分他們的功能。我想這也是我隨著對PHP的深入學習而越來越喜歡這門程式設計語言的原因了吧。下面先給出他們的原型聲明和簡短說明,更多的還是直接看例子代碼吧。bool interface_exists (string $interface_name [, bool $autoload = true ]) 判斷介面是否存在,第二個參數表示在尋找時是否執行__autoload。bool class_exists (string $class_name [, bool $autoload = true ]) 判斷類是否存在,第二個參數表示在尋找時是否執行__autoload。bool method_exists (mixed $object , string $method_name) 判斷指定類或者對象中是否含有指定的成員函數。bool property_exists (mixed $class , string $property) 判斷指定類或者對象中是否含有指定的成員變數。 $value) { print '$key = '.$key. ' => $value = '.$value."\n"; }} class TestClass { public $publicVar = 1; private $privateVar = 2; static private $staticPrivateVar = "hello"; static public $staticPublicVar; private function privateFunction() { } function publicFunction() { output_array("get_class_methods",get_class_methods(__CLASS__)); output_array('get_class_vars',get_class_vars(__CLASS__)); output_array('get_object_vars',get_object_vars($this)); }} $testObj = new TestClass();print "The following is output within TestClass.\n";$testObj->publicFunction(); print "\nThe following is output out of TestClass.\n";output_array('get_class_methods',get_class_methods('TestClass'));output_array('get_class_vars',get_class_vars('TestClass'));output_array('get_object_vars',get_object_vars($testObj)); 運行結果如下: bogon:TestPhp liulei$ php class_exist_test.php The following is output within TestClass.get_class_methods.....................$key = 0 => $value = privateFunction$key = 1 => $value = publicFunctionget_class_vars.....................$key = publicVar => $value = 1$key = privateVar => $value = 2$key = staticPrivateVar => $value = hello$key = staticPublicVar => $value = get_object_vars.....................$key = publicVar => $value = 1$key = privateVar => $value = 2 The following is output out of TestClass.get_class_methods.....................$key = 0 => $value = publicFunctionget_class_vars.....................$key = publicVar => $value = 1$key = staticPublicVar => $value = get_object_vars.....................$key = publicVar => $value = 1 4. get_called_class和get_class: string get_class ([ object $object = NULL ]) 擷取參數對象的類名稱。string get_called_class (void) 靜態方法調用時當前的類名稱。

http://www.bkjia.com/PHPjc/678024.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/678024.htmlTechArticle1. interface_exists、class_exists、method_exists和property_exists: 顧名思義,從以上幾個函數的命名便可以猜出幾分他們的功能。我想這也是我隨著對...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.