Definition of Class
Class Name {
member properties (variables)
}
Note: The first letter of the class name should be capitalized.
A member variable is an integral part of a class, typically a basic data type (an integer, a string), or a complex data type (class, array).
If a PHP file is dedicated to storing classes, the naming convention is
Class name. class.php
Memory storage:
Heap Area: Object
Stack area: basic data type
How to create an object:
$ object Name =new class name ();
Or
$ object Name =new class name;
How to access (use) the properties of an object:
Member properties are public before they can be accessed from the external
$ object Name-> property name;
Cases:
<?php
Class Cat {
Public $name; public $name; is a member variable
Public $age;
Public $color;
}
$cat 1 = new Cat ();
$cat 1->name = "small white";
$cat 1->age = 3;
$cat 1->color = "Yellow";
$cat 2 = new Cat ();
$cat 2->name = "Floret";
$cat 2->age = 10;
$cat 2->color = "white";
if ($cat 1->name = = "small white") {
echo "$cat 1->name". ' <br/> '. "$cat 1->age". ' <br/> '. "$cat 1->color";
}
?>
Description
1. If you pass an object to a function, it actually passes an address;
Cases:
<?php
Class Person {
Public $name;
Public $age;
}
$p 1 = new person ();
$p 1->name = "www.bianceng.cn";
$p 1->age = "10";
When the function passes in the object, the address is passed in
function Test1 ($p) {
$p->name = "Xiao Li";
}
Test1 ($p 1);
Echo $p 1->name; Output Xiao Li
?>
2. If the function is passed a basic data type (integer, Decimal, Boolean, String), by default, the value is passed. If you want to deliver an address, you can use the following form:
function test (& variable ...) {
}
Cases:
<?php
Passing basic data types to functions
$a = 90;
$b = 90.8;
$c = true;
$d = "www.bianceng.cn";
function test1 ($a, $b, $c, $d) {
$a = 78;
$b = 55.3;
$c = false;
$d = "good";
}
Test1 ($a, $b, $c, $d); Call function
echo $a. "||" . $b. "||" . $c. "||" . $d; Output 90| | 90.8| | 1| | www.bianceng.cn
?>
3. In PHP, if you pass an array to a function, the default is to pass the value. If you want to pass in an address, add the address character, as follows:
& Array Name