PHP Object-oriented

Source: Internet
Author: User

<?PHP//Process oriented/*$r =5; $m =3.14* $r * $R;*///classes and objects//objects: Anything can be an object, something that is instantiated by the class//tired: Abstract things from all the same objects//info:code,name,sex,nation,birthday//object: A specific information p001 Zhang San male han 1990-2-3//Defining Classesclassren{var $name;//member Variables    var $age; var $height; var $sex;//generally do not assign a value to a member variable        function__construct ($s)//constructor Function    {        $this->sex=$s; }        functionRun ()//member functions (methods)    {        Echo"This man is running."; }    functionsay () {Echo $this->name. " I'm talking.; $this-run (); }}    //using Class//1. Instantiating an object$r=Newren ("Male");//assigning values to member variables (calling member variables)$r->name= "Zhang San";//assigns a value to the object name//var_dump ($r);//3. Calling member Methods$r->run ();//Execute Member method//access modifier//1. If you want to add an access modifier, you need to remove VAR//2. Three kinds://public publicly//protected protected (can only be used in this class or subclass)/private (only in this Class)//3. If you do not add an access modifier, the default is public//$this reference//$this represents the object (which object is called) and does not represent the class//constructor//1. Special: Function __construct ()//2. Execution Special://3 is executed first when the object is created. Action: Initialize an object?>

PHP Object-oriented

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.