PHP Object-oriented basic concept class and object static property construction/destructor method

Source: Internet
Author: User

1. Traditional process-oriented and modern object-oriented
Traditional process-oriented: refers to the completion of the work is divided into a number of steps to complete one step at a
Modern object-oriented: a task (function) that divides the work that is to be done into one object (functions) each object completes its own task alone
It can be understood as: a cleaning process is a person who finishes the cleaning. Object-oriented is a person sweeping a person to mop the ground
2. Basic object-oriented concepts
Three main features: Package inheritance polymorphism
classes and objects:
Zhang San is an object that Li Si is an object they are all subordinate to the class of people
Class: A concept that describes a certain object with a common characteristic
Object: Refers to a specific object that belongs to a category
Normally, an object cannot be separated from a class, and no object can have a class without a class.
Class human{//Define a category classes is a keyword
//class has some attributes (that is, variables)
var $name = ' Zhang San ';
var $sex = ' Male ';
var $age = ' a ';
//class with some methods (that is, functions)
function Show () {
Echo ' name: '. $this->name. '; Gender: '. $this->sex. '; Age: '. $this->age;
             }
Const PI = 3.14//class has some solid (solid class)
       }  
properties in the class:
definition form (Var is the alias of public):
var $v 1; You can define a value that is not assigned
var $v 2 = 2; Defined simultaneous assignment value cannot be a variable and evaluate an expression
public $v 1;
Public $ = 2;
form of Use:
$ object, property name//property name not preceded by $ symbol
to create an object for the class:
Call
1. Object name = new class name (Human) ();
2. Variable class name
Variable name ($name) = "Class"
Object Name ($lisi) = new variable name ($name) ();
3. Object name = new Self; only internal use of the class refers to itself
function CSelf () {
return new self
}
For example: $lisi = new Human ();
$zhangsan = $lisi->cself ();
The two of them are equal.
4. Object Name 1 = new class name () object Name 2 = new object name 1;
the value of the object:
Value passing: Replication data is independent of each other
Reference passing: Replication is a change of relationship one changes the other
Key Words &;
General Method:
Definition is the same as the use is
Use Also
Access modifiers are not written is public
$this keyword is a pseudo-object that represents the current object of the class that currently belongs
Objects do not display the same content.
system functions:
Gets the class name of an object The result is just a class name string
The result of object name = new class name () Get_class (object name) is the class name
Static properties:
Keyword static
Static $v 1 = 10;
Usage: class:: Attribute name;
static method:
There is no such thing as $this cannot exist.
Construction Method:
Keyword __construct ();
If you don't write, call function ____construct () {
}
Cannot be a static method
Use $this to assign values
destructor Method:
Automatically invoke PHP code execution ends when destroying objects automatically destroy objects available destructors view
You cannot call yourself to perform a physical argument
Manual destruction of unset ($p 1);

PHP Object-oriented basic concept class and object static property construction/destructor method

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.