// What is class? ? ?
Class is a collection of objects with the same set of attributes and services. It provides a unified description of all abstract objects belonging to this class, including its internal properties and services of two main parts
// definition of a class using the class name of the class to write code braces {} internal
// class name to make use of uppercase letter
class Person{ }
// use var to declare a variable interior, but: try not to give this variable initial values, because values are all given initial value after the call
class Person {var $ name; var $ age; etc.} ------
class Person{
var $name;
was $ age;
// method declaration can declare multiple remember, but can not be repeated Oh! ! !
function sun(){
Echo "Singing";
}
}
// instantiate the class keyword to instantiate new class instance variables but after numerous instances of pay can not avoid repeat
$ Obj = new Person (); // parentheses
// $ this can also be used to represent the object, the object to complete the internal members call
function run(){
Echo "My name is:" $ this-> name "My gender is:" $ this-> sex "my age is" $ this-> age "I will sing";......
} // This completes the call to the internal autonomy but these internal variables are outside paid the value is as follows:
// we can use to find the object after the instantiation of the internal variable assignment, the key symbol "->"; he is a special operator to complete the access object members
$ Obj-> name = "Liu Hongji";
$obj->age=”17”;
$ Obj-> sex = "male";
After // var_dump assignment can be used directly to print the object can not be used because the echo echo out of the output can only be a string, this will directly output error
var_dump ($ obj);
// Finally, use the object name to call this method to
$obj->run();
July 2019 Monday 22 May, simply summarize
Guess you like
Origin www.cnblogs.com/xiaojiji/p/11227936.html
Recommended
Ranking