Basic PHP object-oriented writing (different from java)

Source: Internet
Author: User
? Php *** this is a person's object * classClassName {public $ name; public $ age; public $ sex; publicstatic $ mystaticvar11; function _ construct ($ name, $ age, $ sex) {here is its own attribute. You can see that $ this already has a $ attribute. It declares that it is an address and can be changed to another attribute.

? Php/*** this is a person's object */class ClassName {public $ name; public $ age; public $ sex; public static $ my = 'static var11 '; function _ construct ($ name, $ age, $ sex) {// this is an attribute of itself. You can see that $ this already exists. The address is declared, it can be re-enabled differently.

 Public static $ my = 'static var11'; function _ construct ($ name, $ age, $ sex) {// The attribute is already in use, you can see that $ this already has a $ statement. It declares an address. You can use another address $ this-> name = $ name; $ this-> age = $ age; $ this-> sex = $ sex;} function say () {echo "Hello world ";
Echo self: $ my. "\ n ";
} $ Student = new ClassName ("sun", 20, "male"); echo $ student-> say (); echo"
"; Echo $ student-> name; echo"
"; Echo $ student-> age; echo"
"; Echo $ student-> sex; // The call is similar to the java syntax, that is,". "is changed to"-> "?>

The constructor name is also unified _ construct ();

When new is used, a stack space address is allocated to the object area of the heap space.

Call constructor parent ::__ construct () to compare with super. funName () in java

Self: used to access the attributes and methods of this class to access members or methods within the class.

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.