如何在php中设置类成员变量

时间:2014-05-31 06:27:46

标签: php class variables member

设置类成员变量时,我收到以下错误。如何在c#.net

中通常在php中设置成员变量

解析错误:语法错误,意外T_VAR,期待T_VARIABLE,请帮我修复它。我是PHP的新手

<?php

class clsCustomer{

       public var $customercode;
       public var $customername;
       public var $customeraddress;


       public function PrintCustomerDetails(){

        echo $this->customercode." ".$this->customername." ".$this->customeraddress;      
       }

}

$obj = new clsCustomer();

$obj->customercode = 1;
$obj->customername = "Shiv";
$obj->customeraddress = "Mumbai India";

$obj->PrintCustomerDetails();

?>

1 个答案:

答案 0 :(得分:0)

从属性声明中删除var个关键字:

class clsCustomer{

   public $customercode;
   public $customername;
   public $customeraddress;

   ...

}

进一步阅读