<?PHP//Process oriented/*$r =5; $m =3.14* $r * $R;*///classes and objects//objects: Anything can be an object, something that is instantiated by the class//tired: Abstract things from all the same objects//info:code,name,sex,nation,birthday//object: A specific information p001 Zhang San male han 1990-2-3//Defining Classesclassren{var $name;//member Variables var $age; var $height; var $sex;//generally do not assign a value to a member variable function__construct ($s)//constructor Function { $this->sex=$s; } functionRun ()//member functions (methods) { Echo"This man is running."; } functionsay () {Echo $this->name. " I'm talking.; $this-run (); }} //using Class//1. Instantiating an object$r=Newren ("Male");//assigning values to member variables (calling member variables)$r->name= "Zhang San";//assigns a value to the object name//var_dump ($r);//3. Calling member Methods$r->run ();//Execute Member method//access modifier//1. If you want to add an access modifier, you need to remove VAR//2. Three kinds://public publicly//protected protected (can only be used in this class or subclass)/private (only in this Class)//3. If you do not add an access modifier, the default is public//$this reference//$this represents the object (which object is called) and does not represent the class//constructor//1. Special: Function __construct ()//2. Execution Special://3 is executed first when the object is created. Action: Initialize an object?>
PHP Object-oriented