Object-oriented PHP object-oriented concept

Source: Internet
Author: User

The seventh chapter (1) Object-oriented approach-object-oriented concept
What is a class: the process of composing an object is called a class.
What is an object: A class consisting of something called an object.
The relationship between a class and an object: objects are grouped by classes, and classes have objects.
What is a member property: Defines a member static description. such as: person's name, sex, height, weight ...
What is a member method: defines a dynamic description of a member. Can achieve some of the functions such as: People can eat, walk, drive, talk ...
How to abstract a class:
Class name such as: human
{
Member properties: Name, height, weight ...
Member method: Walk, Talk, eat, drive ...
}
Examples:
class keyword Person class name first letter to capitalize
{
Member properties
var keyword $name; name
var $age; age
var $sex, sex ...
Member Methods
function keyword say ()
{echo "I'm Talking";}
function Run ()
{echo "I'm Walking";}
Function Eat ()
{echo "I'm Eating";}
}
To produce an instantiated object:
$P 1=new keyword person class name;
$P 2=new person;

The seventh chapter (3) Object-oriented detailed _ Object instantiation and use
How to instantiate an object
Example Description:
Class Ren
{
var $xingming;
var $nianling;
var $xingbie;
var $shouji;
function Shuohua ()
{echo "I'm Talking <br>";}
function Zoulu ()
{echo "I'm walking <br>";}
function Chifan ()
{echo "I'm eating <br>";}
}
Class Shouji
{
var $pinpai;
var $yanse;
var $chiceng;
function Dadianhua ()
{}
function Jiedianhua ()
{}
function Faxinxi ($ren, $xinxi)
{$ren->shouji->shouxinxi ($xinxi);}
function Shouxinxi ($xinxi)
{echo "Access info". $xinxi. " <br> ";}
}
instantiated. Person:
$r 1=new Ren ();    $r 2=new Ren (); $r 3=new Ren ();
instantiated. Person's name:
$r 1->xingming= "John";    $r 2->xingming= "Dick"; $r 3->xingming= "Harry";
instantiated. Mobile Phone:
$s 1=new Shouji ();    $s 2=new Shouji (); $s 3=new Shouji ();
instantiated. Human Mobile:
$r 1->shouji= $s 1;    $r 2->shouji= $s 2; $r 3->shouji= $s 3;
instantiated. Human Hair message:
$r 1->shouji->faxinxi ($r 2, "Hello");
Output: Receiving information Hello

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.