Create a simple PHP object .? Php defines a digital Tyrannosaurus class classDigimon {var $ name; var $ hitPoint; var $ attack; var $ defense; functionattack () {echoattack;} creates an agu $ agunewDigimo object from the class Digimon
Name = "agu"; $ agu-> hitPoint = 50; $ agu-> attack = "12"; $ agu-> defense = "18 "; // The field echo $ agu-> name of the access object agu. "The lifecycle is ". $ agu-> hitPoint."
"; Echo $ agu-> name." attack power is ". $ agu-> attack ."
"; Echo $ agu-> name.": ". $ agu-> defense ."
"; // Method echo $ agu-> name." The current action is "; echo $ agu-> attack ();?>
Program output:
The lifecycle of the yagu beast is 50.
The yagu attack capability is 12.
The defensive capability of the yagu beast is 18.
The current yagu action is attack.
The code demonstrates how to create a class, how to create objects from the class, how to access object fields, and how to access objects.
PHP's OOP programming is similar to Java's. if there is a basis for Java programming, PHP's OOP programming is quite easy to use.
Http://www.bkjia.com/PHPjc/752581.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/752581.htmlTechArticle? Php // defines a class Digimon {var $ name; var $ hitPoint; var $ attack; var $ defense; function attack () {echo "attack ";}} // create an object agu $ agu = new Digimo from the class Digimon...