0607PM Cloning & Referencing classes & Loading classes & Object-oriented Chuanjiang & function overloading

Source: Internet
Author: User

Cloning
Class Ren
{
Public $name;
Public $sex;
function __construct ($n, $s)
{
$this->name= $n;
$this->sex= $s;
}
function __clone ()//change the contents of the cloned object
{
$this->name= "Li Sisi";//this represents the Replica object
$that->name= "Li Sisi";//that represents the original, and later abandoned.
}
}
$r =new Ren ("Zhang Dan", "female");
Cloning, not very useful, can completely new
$r 1=clone $r;
Var_dump ($R);
Var_dump ($r 1);

Referencing classes, loading classes
Class Ren
{
Public $name;
Public $sex;
Public Function Say ()
{

}
}

About the root path: PHP inside/representing the root path; value the disk where the file resides, cook a chestnut: d:/
HTML inside/representing root path: refers to server folder
Include ("Ren.class.php");//relative path "/" Root Path

Require "Ren.class.php";
Require_once ("Ren.class.php");

Auto Load Class
1. All class file naming requirements have the same rule
2. There must be a class name inside the file name
3. All class files must be in the same folder
function __autolode ($classname)
{
Require $classname. " Class.php ";
}
$r =new Ren ();
Echo $r->name;

Object-Oriented Large Chuanjiang


Classes and objects
Object: Everything can be considered an object, and an object is an instantiation of a class.
Class: A class is an abstraction of an object that describes a feature common to many objects.

Defining Classes Class
member variables and Member methods
Access modifier Public Private protected protected
Object-oriented three major features:
1. Encapsulation: Purpose: Protection class, procedure: Member private, method access. __get () __set ()
Construction method: Special point: 1. Special 2. The execution time is special; the initialization of the member can be implemented
$this Keyword: $this represents the Object

2. Inheritance: Subclasses can inherit everything from the parent class
Features: Single inheritance: A subclass can have only one parent class, and a parent class may derive multiple subclasses.
Method overrides: A method that has the same name as the parent class in the subclass overrides the parent class method, if you want to extend the method of the parent class instead of overwriting: Parent::say ();

3. Polymorphism: When the parent class refers to a subclass instance, the parent class reference is polymorphic when the method is called, because the child class overrides the method of the parent class.
Conditions: 1. Must inherit 2. Subclasses must override the parent class Method 3. Parent class reference to child class instance

Static
Keywords: static
An ordinary member belongs to an object.
A static member is a class-owned
Static members can be called in normal methods
Static methods cannot invoke ordinary members
Called with the class name: Ren::say ();
Self Keyword: represents the class itself

Abstract class
Keywords: abstract
Abstract classes cannot be instantiated and can be inherited

Interface
Keyword: interface, do not add class keyword
There are member methods inside the interface, but there is no function body.
Implements the keyword used by the interface: implements is not extends
Subclasses must implement all methods of the interface

Destructors
Special execution Special: Execute when object is destroyed

__tostring () method

Clone keyword: clone

7 Types of Load classes

function overloading
Requirements: 1. Either the number of parameters is different or the parameter type is different. 2. Method names must be the same

Function overloading: Strongly typed language, PHP does not have
Requirements: 1. Either the number of parameters is different, or the parameter type is different 2. Method names must be the same

0607PM Cloning & Referencing classes & Loading classes & Object-oriented Chuanjiang & function overloading

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.