1211php Object Oriented

Source: Internet
Author: User

First, you need to define the array, $attr = Array (directly to the elements) indexed arrays

Associative array $attr = Array ("one" =>1,2,3)

for ($i =0; $i <count ($attr); $i + +) iterating through an indexed array cannot traverse an associative array

The foreach traversal associated index can traverse

foreach ($attr as $k = $v)
{
$v;
}

Object-oriented classes and objects

Example:

$yuan = new Yuan ();
$yuan->banjing = 10;
echo $yuan->mianji ();
Var_dump ($yuan);

$this keyword represents the object inside a class

Build a great circle
$maxyuan = new Yuan ();
$maxyuan->banjing = 10;

Build a small Circle
$minyuan = new Yuan ();
$minyuan->banjing = 5;

echo $maxyuan->mianji ()-$minyuan->mianji ();

Class Yunsuan
{
Public $a = 10;
Public $b = 5;

Construction method
function __construct ($a 1, $b 1)
{
$this->a = $a 1;
$this->b = $b 1;
}

destructor, which executes when the object memory is released
function __destruct ()
{
echo "The object was released";
}

Private Function Jia ()
{
return $this->a+ $this->b;
}

function Jian ()
{
return $this->a-$this->b;
}

function Cheng ()
{
return $this->a* $this->b;
}

function Chu ()
{
return $this->a/$this->b;
}


}

Created objects
$y = new Yunsuan (10,5);

Var_dump ($y);
echo $y->chu ();


Access modifiers
Public, accessible anywhere
Protected is protected and can only be accessed in that class or subclass of that class
Private, accessible only in this class

The method at the beginning of __ becomes the Magic method in object-oriented

constructor function
1. Special wording: Method name Special
2. Execution time is special: When the object is created, it is executed.

Initialize a member inside an object

1211php 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.