1 <?php
2 header("Content-Type:text/html;charset=utf-8");//调整为utf-8编码格式
3 class car
4 {
5 var $version;
6 var $money;
7 var $color=green;
8
9 function __construct($para1,$para2,$para3){
10 $this->version=$para1;
11 $this->money=$para2;
12 $ this -> Color = $ Para3 ;
13 is
14 } // constructor is called automatically when new a new object, which need to pass three parameters, $ this pointer, the parameter value assigned to car three attributes
15
16 function carInfoPrint () {
. 17 echo $ the this . -> Version "car, its price is:." $ the this -> Money ", its color is:.". $ the this -> color;
18 is }
. 19
20 is }
21 is
22 is CAR1 $ = new new cAR ( "BMW", "200W", "Red" ); // new new car car1, and assign property values
23 $ CAR1 -> carInfoPrint ();// car1 call its carInfoPrint () method
24-
25 ?>
show result: