PHP Object-oriented members in-depth PHP object-oriented PHP is Object oriented PHP object-oriented

Source: Internet
Author: User
Tags object oriented php
Members of the class:
1. Constant: const constant name = value;

2. Properties
2.1 Static Properties
2.2 Instance Properties

3. Methods
3.1 Static methods
3.2 Example Methods
3.3 Construction methods
3.4 destructor Method

Attention:
① static properties are classes that share this property with objects created by this class
static properties and static methods can be used in ② instance methods
③ static methods can not access instance properties and instance methods, because the static belongs to the class, the instance belongs to the object, class when the object is not new out!


    Header"Content-type:text/html;charset=utf-8"); classC{ConstPATH ="C:/windows";//class cannot use define to define constants//static propertiesStatic$count= the;//equivalent to static public $count =;//Instance Properties Public$name="Tom";//equivalent to var $name = "Tom";//Default parameterless constructor//function __construct () {////echo "
__construct is called without a reference to the constructor method;//}//parameter constructor, commonly used for initialization of class member properties, only one constructor can exist for a class in PHP function__construct($name){$this->name =$name;Echo"
The __construct constructor method is called ";}//Instance method functioninstancefun(){Echo"
The instance method is called ";Echo"
Access Constants in Instance methods: ". Self::P Ath;Echo"
Access instance properties in instance method: {$this->name} ";Echo"
To access a static property in an instance method: ". Self::$count;//self represents the class itself .//Call a static method in an instance method Self:: Staticfun ();}//static methodStatic functionstaticfun(){Echo"
The static method is called ";Echo"
Access Constants in Static methods: ". Self::P Ath;Echo"
To access static properties in a static method: ". Self::$count;//Note: Instance properties cannot be accessed in a static method}//destructor, which is called by the system when the object is destroyed//Normally the code is executed and the object is destroyed function__destruct(){Echo"
Object {$this->name} is destroyed ";}}$object=NewC"Harry Potter");$object->instancefun ();Echo""; C::staticfun ();//The following code causes the object that $object points to be destroyed//$object = null;//$object = new C ("Qin Shihuang");//$object = 3;//unset ($object);Echo"
Program last line of code ... ";

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP object-oriented members, including the object-oriented, PHP content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.