PHP Learning Note class declaration and object instantiation _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/* Declaration of Class
* 1. What are you going to develop, determine what class to write
* 2. Members of the class must belong to this class
* [modifier class's Keywords] class class name {
* Member Properties:
* Member Method:
* }
* 3. When declaring member properties in a class, there must be a modifier in front of it, using VAR or public when unsure which word to use
* One file holds only one class, and the file name contains the class name, the document: class name. class.php
* The notation of the class name:
* Variable: AAABBBCCC
* Function: AAABBBCCC
* Constant: AAABBBCCC
* Class Name: AAABBBCCC
* 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 good object and then give the values
*
*
* Instantiate objects by class
* 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 have storage space inside
*
* Role of the object
*
* Allocation of objects in memory
*
* Use of objects
* Members in an object must be accessed by reference to the object
* Objects, Members
*
* Object--member properties
* Object--member method
*
*
*
*/
Declaration of class (phone class)
Class phone{
declaring properties
var $pinPai;
var $color;
var $batteryCapacity;
var $screenSize;
Member Methods
function call () {
}
Function message () {
}
function Playmusic () {
}
function photo () {
}
}
Instantiation of a class
Class person{
var $name;
var $age;
var $sex;
function say () {
}
Function Eat () {
}
function Run () {
}
}
Instantiation of
$p 1=new person;
$p 2=new person;
$p 3=new person;
Accessing the members of an object
$p 1->name= "Zhangsan";
Echo $p 1->name;
?>

http://www.bkjia.com/PHPjc/323522.html www.bkjia.com true http://www.bkjia.com/PHPjc/323522.html techarticle Copy the code as follows:? Declaration of the PHP/* class * 1. What you want to develop, determine what class to write * 2. Members of the class must belong to this class * [modifier class keyword] class name {...

  • Related Article

    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.