PHP-------Object-oriented

Source: Internet
Author: User

Object oriented

First, Class and object:

Concept of the "1" object: Anything can be called an object, and the class is instantiated. (We are able to see everything that can be called objects)

"2" class concept: for all the same class of objects, we abstract out of things. For example: Our class, all students, have a common thing, our class number is the same, we learn the same course, we have the same time in class, then these same things we can take out alone, make a class, this class is a class of classes, for example, we people, Everyone has a common thing, a person, there are two eyes, a nose, a mouth, two ears, two arms, two legs, these are common human things, everyone has, if not the words are incomplete, we take these things out, he can also be called a class, this class is human, As long as you meet human standards, they are called human beings. (The abstraction of something similar is a class.) )

Second, define the class:

defining a class requires just a keyword class followed by a custom category name, plus a curly brace. The first letter of the class name should be capitalized. A class consists of two things: a member variable or a member property, a member method, or a member function.

Example:

Class Ren

{

Member variables

Member Methods

}

Iii. making objects (instantiating objects)

Use the new keyword only and add a method followed by the same name as the class name. of course, if you do not need to pass arguments to an object when instantiating it, you can use the class name directly after the new keyword, and you do not need to add parentheses.

The name of the $ variable name =new class ([parameter list]);//Object Instantiation format

Or

$ variable name =new class name;//object instance formatting, no arguments are required for the object

Example:

$r =new Ren ();

Iv. calling members in an object

$ reference Name, member property = value

PHP-------Object-oriented

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.