0426 Process-oriented

Source: Internet
Author: User

Process oriented
Classes and objects anything can be called an object class instantiation of something that is a concrete piece of information
The abstraction of a class to all the same objects

Defining classes
Class Ren
{
var $name;//called member variable
var $age;
var $height;
var $sex; Do not assign a value to a member variable on one side

function __construct ($s)//constructor
{
$this->sex= $s;
}

function run ()//member functions (method)
{
echo "This man is running";
}
function Say ()
{
echo $this->name. " is talking ";
}
function __destruct ()//destructor object called before destruction
{
echo "The object to destroy";
}
function Setage ($a)//functions assigned to age
{
if ($a >10&& $a <50)
{
$this->age= $a;
}
}
function getage ()//value of age
{
return $this->age;
}
function __set ($name, $value)//Magic method for assigning a value to a private member inside a class * * *
{
$this $name = $value;
}
function __get ($name)//Magic method for the value of private members inside a class * * *
{
return $this $name;
}
}

Using classes
1 Instantiation of objects
$r =new Ren ("male");
2 assigning values to member variables (calling member variables)
$r->name= ' Zhang San '; Assigning a value to an object name
$r->setage (30);
$r->name= "John Doe";//Executes the statement automatically calls the __set method $r->__set ("name", "John Doe")
Var_dump ($R);
3 Member Methods
$r->say ();//Execute Member method
Access modifier public
1 If you want to add access modifiers you need to remove Var
2 access modifiers have three public protected protected PRIVATC private (can only be used in this class)
3 If no access modifier is public by default

$this reference It represents the object (which object call represents it).

constructor function
1 Special __construct

2 Perform the first execution of special objects at the time of creation
Action: Initialize an Object

Three main features of object-oriented
Packaging
Purpose: To make the class more secure and not allow direct access to the member variables within the class
Procedure: 1 Make the member variable private (PRIVATC)
2 To do a method to implement the value of a variable or to assign a value in the method to add a restriction condition

Using the Magic method in the class can also implement the operation of the private member

__set () Features: automatic execution, the variable name in the assignment statement as the first parameter, the variable name as the second parameter call __set () method

__get () Feature: automatically executes the variable name in the assignment statement as a parameter call __get () method

0426 Process-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.