About the class we all have a certain understanding here only in PHP class noteworthy places
The creation of----class----
PHP uses the keyword class to create a class and uses a pair of curly braces
Such as:
Class name{public $n = ""; Private $u = ""; Public Function name () { $n = "233"; $u = "23333"; } Public function Rename ($newn) { $this->n= $newn;//this represents this class }}
The end does not score the number. $n, $u is a field; name () is a constructor (__construct () can also define a constructor, as described below), you can assign a value to a field; Rename () is a method.
----field----
Comparison
$obj =new name ();
Echo $obj->n;
And
$obj =new name ();
Echo $obj->u;
The former can be executed, and the latter cannot be declared private before $u. This is similar to C + +.
Code:
public static $nm = "2333333333333333";
A static field is declared for the function.
Through the class name and:: You can access the variable directly
echo Name:: $nm;
This is similar to C + +.
In PHP, you can also access static fields in a class by self::+$+ variable names, where self is equivalent to $this->.
The use of methods is similar to fields
----constructor----
Constructors have the same name as classes in PHP5 and earlier versions
In PHP5 and later versions, the magic word __construct () can define constructors
Magic word __construct () to define constructors
Class name{public $n = ""; Private $u = ""; Public Function __construct () { $n = "233"; $u = "23333"; } Public function Rename ($newn) { $this->n= $newn; }}
Constructors can have parameters
__construct ($name = "", $sex = "man", $age =0) {}
When declaring an object
$obj = new name ("I", "man", 28);
If no argument is given, the default is = after value.