An example of understanding PHP object-oriented programming (OOP), oop_PHP tutorial for object-oriented programming

Source: Internet
Author: User
An example of understanding PHP object-oriented programming (OOP), object-oriented programming (oop. An example of understanding PHP object-oriented programming (OOP), object-oriented programming (oop? PhpclassPerson {declares a new public variable $ name, which can be accessed by classes in any package. public $ an instance that understands PHP object-oriented programming (OOP) and object-oriented programming (oop)

 
Class Person {

// Declare a new public variable$ NameCan be accessed by classes in any package
Public $ name; public $ sex; public $ age;

// Declare a method of this class function say () {echo "Hello!
"; Echo" My name is: ". $ this-> name ."
"; Echo" my gender is: ". $ this-> sex ."
";}}
// Declare the new Student class as the child class of Person Student extends Person {public $ school; function study (){
// Parent: Can be used to call the member methods defined in the parent class.
Parent: say (); echo "My age is:". $ this-> age ."
I am going to school at ". $ this-> school. ";}}
// You only need to define P1 as a Student class $ p1 = new Student ();

// Assign $ P1-> name = "Zhangsan"; $ p1-> sex = "male" to the name, sex, age, and school attributes of p1 "; $ p1-> age = "18"; $ p1-> school = "XX school"; $ p1-> study ();?>

The browser output result is as follows:

Hello!
My name is: Zhang San
My gender is: Male
My age is: 18
I am going to school at xx school.

Examples of objective (OOP), object-oriented programming (oop? Php class Person {// declare a new public variable $ name, which can be accessed by classes in any package. public $...

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.