Declaration of a PHP class and object instantiation

Source: Internet
Author: User
<?php/* class declaration * 1. What do you want to develop, determine what class to write * 2. The members of the class must belong to this class * [modifier class's Keywords] class class name {* member Property: * Member Method: *} * 3. When declaring a member property in a class, a modifier must precede the Not sure which word to use, use VAR or public * A file holds only one class, the file name contains the class name, the file: class name. class.php * Class Name: * Variable: AAABBBCCC * Function: AAABBBCCC * Constant: AAABBBCCC * class Name: Aa ABBBCCC * 4. member properties in the class, if you create multiple objects, each object has a different property value, do not give the initial value directly, after creating the object and then give the values * * * through the class to instantiate the object * 1. Use new to create a new object, plus the class name, which is the object that created the class * $ object reference =new class name; * 2. As long as there is a new keyword is to create an object, create an object is to allocate a space in memory * * Only objects are stored within the storage space * * Object in memory allocation * * object's use * The members of the object must access the object by reference to the * object , member, member property, member Properties * Object---Members Method * * * * *//class declaration (Phone Class) class phone{//Declaration attribute Var $pinPai var $color var $batteryCapaci Ty var $screenSize; Member method function call () {} function message () {} function Playmusic () {} function photo () {}}//Class instantiation class person{var $n Ame var $age; var $sex; function say () {} function Eat () {} function run () {}}//instantiation $p 1=new person; $p 2=new person; $p 3=new person; Access the members of the object $p 1->name= "Zhangsan"; echo $p 1->name;?>

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.