Mobile app interface programming technology-Learning and implementation of PHP advanced classes and objects

Source: Internet
Author: User
: This article mainly introduces mobile app interface programming technology-PHP advanced classes and objects for learning and implementation. For more information about PHP tutorials, see.
  • Create classes and objects

  Name ;}}$ car = new Car (); echo $ car-> name .'
'; Echo $ car-> getName ();
  • Class attributes

Attribute declaration starts with the keyword public, protected, or private, followed by a common variable declaration. Attribute variables can be set to the default value for initialization. the default value must be a constant.

The keyword of access control indicates:
Public: public
Protected: protected
Private: private

The default value is public, which can be accessed externally. Generally, you can use the-> object operator to access the attributes or methods of an object. for static attributes, you can use the: double colon to access the object. When calling the class member method internally, you can use the $ this pseudo variable to call the attributes of the current object.

Protected attributes and private attributes cannot be called externally. they can be called within the member methods of the class.

  • Class method

Like attributes, class methods also have public, protected, and private access control.

The static modifier is called a static method. the static method does not need to be instantiated. it can be called directly by class name. The operator is double colon ::.


  Speed + = 10;} publicstatic $ name = 'jarlen'; publicstaticfunctiongetSpeed () {return 'jar' ;}}$ car = new Car (); $ car-> speedUp (); echo $ car-> speed; echo'

'. Car: $ name .'

'; Echo Car: getSpeed ();

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the mobile app interface programming technology-Learning and implementation of PHP advanced classes and objects, including content, hope to be helpful to PHP tutorials.

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.