Object-oriented classes (class) in PHP

Source: Internet
Author: User

2.11 a.m. is about object-oriented classes (class), a very abstract concept,

The definition of members within a class is public$abc; PRIVATE$ABC (private variable); protect $ABC (protected variable);

Here is an example to explain the class

<?PHPclasstest_123{ Public $a;  Public $b; functionSquar () {return $this->a*$this->b;//here is the area of the rectangle, because the definition in class is abstract, so we need to instantiate the A.B      }    } $shili=NewTest_123 ();//instantiate the above class  $shili->a=3; $shili->b=4;//Instantiate A, b$return=$shili-Squar ();Var_dump($return)?>

The output value is int (12);

Or it's easier to write in other ways.

<?PHPclasstest_123{functionTest_123 ($k,$v)//You can also use __construct to construct a frame by defining a B directly here.    {       $this->a=$k; $this->b=$v; }      functionSquar () {return $this->a*$this->b;//here is the area of the rectangle, because the definition in class is abstract, so we need to instantiate the A.B      }    } $shili=Newtest_123 (3,4);//instantiate the above class Var_dump($shili-Squar ())?>

The above example can help us to better understand the concept of the class, relative to the theory is not so boring

Object-oriented classes (class) in PHP

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.