: 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 ();
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.
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.