PHP learning and PHP Learning

Source: Internet
Author: User

PHP learning and PHP Learning
Class:
1. Similar objects are classified into a class by means of classification.
2. The class defines the same attributes and methods of these similar objects.
3. The class object is called an instance of the class.
4. class attributes and methods are collectively called class members.


Implement through a class
1. How to define a class
2. How to instantiate class objects

3. How to call class methods

<? Php // class definition starts with the keyword class, followed by the class name class ceshi {// defines the attribute public $ a = "ceshi"; // defines the method, function ceshifunction () {echo "this is a test method" ;}}// class instantiation $ ceshi = new ceshi (); // obtain the attribute value echo $ ceshi->. "<br/>"; // obtain the class method echo $ ceshi-> ceshifunction (). "<br/>";?>
4. Constructor
5. destructor

<? Php // class definition starts with the keyword class, followed by the class name class ceshi {// defines the attribute public $ a = "ceshi "; // The constructor will directly execute this function when calling the class. You can pass parameters in function _ construct ($ info) {$ this-> a = $ info} // destructor. When the execution ends, when the variable is null, run the // destructor, which is usually used to clean up the resource function _ destruct () {echo "program execution ends ". $ this-> a;} // define the method. function ceshifunction () {echo "this is a test method ";}} // class instantiation $ ceshi = new ceshi ('another variable '); // obtain the attribute value echo $ ceshi->. "<br/>"; // You can trigger the Destructor $ ceshi = null by setting the variable to null. // obtain the class Echo $ ceshi-> ceshifunction (). "<br/>";?>



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.