Accessing properties and Methods _php Tutorial

Source: Internet
Author: User
Tags access properties php class
accessing properties and Methods

A property of an object instance is a variable, just like any other variable in PHP. However, you must refer to them using the-I operator. You do not need to use the dollar symbol $ before the property.

can be associated with-> If an object's properties contain an object, you can use the two-by operator to get the properties of the inner object. You can even place these expressions with double-referenced strings.

Access methods and access properties are similar. The operator is used to point to the method of the instance. The method executes almost the same as a function outside the class.

If one class inherits from another, the properties and methods in the parent class will be valid in the subclass, even if there is no declaration in the subclass. As mentioned before, inheritance is very powerful. If you want to access an inherited property, you only need to refer to it as you would access the base class's own property, using the:: operator.

     

PHP has two special namespaces: the parent namespace points to the parents class, and the self namespace points to the current class. Example 6.6 shows how to use the parent namespace to invoke constructors in the parent class. Also use self to invoke another class method in the constructor.

 
      

If you need to determine the name of a variable at run time, you can use $this-> $Property such an expression. If you want to invoke the method, you can use $obj-> $method ().

You can also use the-I operator to return the value of a function, which is not allowed in previous versions of PHP. For example, you could write an expression like this: $obj->getobject ()->callmethod (). This avoids the use of an intermediate variable and also helps implement some design patterns, such as the factory pattern.


http://www.bkjia.com/PHPjc/446726.html www.bkjia.com true http://www.bkjia.com/PHPjc/446726.html techarticle accessing properties and methods a property of an object instance is a variable, just like any other variable in PHP. But you have to use the-I operator to refer to them. You do not need to use the dollar symbol $ before the property .

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