简体   繁体   English

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

[英]How to set Class member variables in php

I'm getting following error shown below while setting class member variables. 设置类成员变量时出现以下错误。 How to set member variables in php like we normally do in c#.net 像我们通常在c#.net一样,如何在php中设置成员变量

Parse error: syntax error, unexpected T_VAR , expecting T_VARIABLE ,Kindly help me out to fix it. 解析错误:语法错误,意外T_VAR ,期望T_VARIABLE ,请帮我解决它。 I'm newbie in PHP 我是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();

?>

Remove the var keywords from the property declarations: 从属性声明中删除var关键字:

class clsCustomer{

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

   ...

}

Further Reading 进一步阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM