PHP Object-oriented-class constants _php Tutorial

Source: Internet
Author: User

PHP Object-oriented-class constants


PHP Object-oriented-class constants

Class constants: A class that holds unchanged data for the duration of a run.

Defined:

const keyword

const constant NAME = constant value

Example:

Class Student

{

Public $stu _id;

Public $stu _name;

Public $stu _gender;

Const Gender_male = ' Male ';

Const Gender_female = ' female ';

}

Class constants are not restricted by access-qualified modifiers

Access:

Class:: Constant Name

Example:

Class Student

{

Public $stu _id;

Public $stu _name;

Public $stu _gender;

Const Gender_male = ' Male ';

Const Gender_female = ' female ';

Public function __construct ($id, $name, $gender = ")

{

$this->stu_id= $id;

$this->stu_name= $name;

$this->gender= ($gender = = ")? Self::gender_male: $gender;

}

}

Summary: Members that can be defined in a class: constants, static properties, non-static properties, static methods, non-static methods.

Note: $this represents the current object and always represents the object of the class where $this is located?

No, because the value of $this does not depend on the class in which the $this resides, but on the execution object (execution Environment) when the $this method is called.


The execution environment of the method in which the current method is executed in the context of the object, within the method

$this represents which object.

http://www.bkjia.com/PHPjc/871194.html www.bkjia.com true http://www.bkjia.com/PHPjc/871194.html techarticle PHP Object-oriented-class constant PHP Object-class constant class constant: a class that holds unchanged data for the duration of the run. Definition: const keyword Const constant NAME = Constant Example: ...

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