PHP class and Object function examples _php tutorial

Source: Internet
Author: User
Tags autoload function examples
1. Interface_exists, Class_exists, Method_exists and property_exists: As the name implies, you can guess a few of their functions from the names of the above functions. I think that's why I'm becoming more and more fond of this programming language as I learn more about PHP. Let's start with their prototype declaration and brief description, and more or just look at the example code. BOOL Interface_exists (String $interface _name [, bool $autoload = True]) determines whether the interface exists, and the second parameter indicates whether __autoload is executed when the lookup is performed. BOOL Class_exists (String $class _name [, bool $autoload = True]) determines whether a class exists, and the second parameter indicates whether __autoload is executed on lookup. BOOL Method_exists (mixed $object, string $method _name) determines whether the specified class or object contains the specified member function. BOOL Property_exists (mixed $class, string $property) determines whether the specified class or object contains the specified member variable. $value) {print ' $key = '. $key. ' = = $value = '. $value. " \ n "; }} class TestClass {public $publicVar = 1; private $privateVar = 2; static private $staticPrivateVar = "Hello"; static Pu Blic $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 ();p rint "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)); The results of the operation are as follows: 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 = = = = = = = Privatevar = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2$key $value Ublicvar = $value = 1$key = Privatevar = + $value = 2 The following is output out of testclass.get_class_methods .... .... $key = 0 = $value = publicfunctionget_class_vars ... $key = Publicvar = = = = =/=/= =/=/=/=/=/=/=/= 1$key = Staticpublicvar = + $value = get_object_vars ... $key = Publicvar = = = = = 1 4. $value = = =. Get_called_class and Get_class:string get_class ([Object $object = NULL]) Get the class name of the Parameter object. The current class name when a string get_called_class (void) static method is called.

http://www.bkjia.com/PHPjc/678024.html www.bkjia.com true http://www.bkjia.com/PHPjc/678024.html techarticle 1. Interface_exists, Class_exists, Method_exists and property_exists: As the name implies, you can guess a few of their functions from the names of the above functions. I think that's what I'm going to do with ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.