name = "Agur beast", $agu-hitPoint = $agu, $agu, attack = "n"; defence = "18";//the field that accesses the object Agu echo $agu name ." The health value is ". $agu-HitPoint."
"; Echo $agu, name." The attack is ". $agu-attack."
"; Echo $agu, name." The defensive force is ". $agu, defence."
";//the method of accessing the object Agu echo $agu, name." The current action is "; Echo $agu-attack ();? >
Program output:
The Agur beast has a health value of 50.
Agur Beast's attack is 12.
The Agur Beast has a defensive force of 18.
Agur Beast currently moves for attack
In the code, there is a clear demonstration of how to create a class, how to create an object from a class, how to access the fields of an object, and how to access the object.
PHP's OOP programming is almost the same as Java, and if you have a Java programming base, PHP's OOP programming is fairly easy to get started with.
http://www.bkjia.com/PHPjc/752581.html www.bkjia.com true http://www.bkjia.com/PHPjc/752581.html techarticle php//defines a digital Tyrannosaurus class Digimon{var $name, Var $hitPoint, var $attack, var $defence, function Attack () {echo "Attack";}} Create object from class Digimon Agu$agu = new Digimo ...