1. Development and interpretation:
Compilation: Machine oriented
C language: Process oriented
Java : Object-oriented
PHP : Supports object-oriented
In fact, the class is also a data type
a . classes are abstract and represent a class of things
B. object is specific and is a concrete instance of the class
c. A class is a template for an object that is an individual instance of a class
2. Simple Introductory case :
<?phpclass Cat{public$name;public$age;public$color;} $cat 1=newcat ();//Instantiate a class/create an object/instantiation object the same meaning $cat1->name= "small white"; $cat 1->age=10; $cat 1->color= "Red"; $ findcat= "Small white", if ($cat 1->name== $FindCat) {ECHO $FindCat. " Exist ";} ?>
3. Usage
a . description of the member property:
A member property is extracted from something, which can be a basic data type (integer, Decimal, Character, Boolean), or a composite data type (array, object)
Class class name {
member Properties ;
}
b . Creating Objects :
$ Object Name =new class name ();
Or
$ Object Name =new class name ;
C . Accessing Object Properties
$ Object Name - Property name ;
D . class Naming Conventions
If a file is specifically used to define a class, there is no class operation, its naming specification:
class name . class.php
Class class name
{
}
4. Detailed explanation from memory
Memory diagram
Heap Area : objects, usually with smaller
Stack Area : Basic data class, generally larger
Case 1 :
<?phpclass Cat{public$name;public$age;public$color;} $c =90, $cat 1=newcat (), $cat 1->name= "small white", $cat 1->age=10; $cat 1->color= "Red"; $cat 2= $cat 1?>
The memory graph is as follows:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/45/wKiom1c8Z9iykK8RAAAzOWpI1iQ198.png "title=" capture. PNG "alt=" Wkiom1c8z9iykk8raaazowpi1iq198.png "/>
Case 2 :
<?php$a=9; $b = $a; $b = $b +8; echo$a. " ". $b;? >
The memory graph is as follows:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/43/wKioL1c8aSHyywNVAAAVtUW8sxo431.png "title=" capture. PNG "alt=" Wkiol1c8ashyywnvaaavtuw8sxo431.png "/>
Case 3 :
<?php$a=9; $b =& $a; $b = $b +8; echo$a. " ". $b;? >
The memory graph is as follows:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/45/wKiom1c8aJzwpUSjAAAU-Qt24LY108.png "title=" capture. PNG "alt=" Wkiom1c8ajzwpusjaaau-qt24ly108.png "/>
Case 4:
<?phpclassperson{public $name; Public$age;} $p 1=newperson (); $p 1->name= "Xiao Ming"; $p 1->age=10; Functiontest1 ($p) {$p->name= "Floret";} Test1 ($p 1); Echo$p1->name;? >
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/43/wKioL1c8agzRrmsMAAAwciKnVnU476.png "title=" capture. PNG "alt=" Wkiol1c8agzrrmsmaaawciknvnu476.png "/>
a. when the function receives the object, it receives the value address ?
B. if it is a basic data type? By default , A value is passed If you want to pass in an address :
functiontest (&$ variable name )
{
}
in the PHP , if you pass an array to a function, it is passed by default (a new array is copied), if you want to pass in an address :
FunctionTest (&$array)
{
}
Problem?
<?php$arr=array ($a 1, $a 2), $a 1=array, $a 2=array (4,5,6,7), foreach ($arr as $k + = $v) {echo "$k = $v";} Var_dump ($arr);? >
..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... .. ....... ..... difference
<?php$a1=array, $a 2=array (4,5,6,7), $arr =array ($a 1, $a 2), foreach ($arr as $k + = $v) {echo "$k = $v";} Var_dump ($arr);? >
Error
This article is from "Uncle Wei Xiaobao" blog, please be sure to keep this source http://darmi.blog.51cto.com/11607923/1774885
Getting Started with PHP object-oriented programming