Create a simple PHP object _php Tutorial

Source: Internet
Author: User
 
  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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.