具有声明的类构造函数错误

时间:2012-04-19 21:56:04

标签: php class

我收到错误,NetBeans告诉我它在$ xml_package声明的最后一行上有所期待。我缺少什么想法?

谢谢。

class foo
{
    public function __construct()
    {
        public $rateRequest = 'RateV4Request';

        public $xml_request = '<'. $rateRequest. '><Revision></Revision></'.
                              $rateRequest. '>';

        public $xml_package = '<Package><Service></Service><ZipOrigination>
                        </ZipOrigination><ZipDestination></ZipDestination>
                        <Pounds></Pounds><Ounces></Ounces><Container>
                        </Container><Size></Size></Package>';
    }
}

1 个答案:

答案 0 :(得分:3)

那是因为你在构造函数本身声明属性,而不是在类

class foo 
{ 
    protected $rateRequest; 

    protected $xml_request; 

    protected $xml_package; 

    public function __construct() 
    { 
        $this->rateRequest = 'RateV4Request'; 

        $this->xml_request = '<'. $this->rateRequest. '><Revision></Revision></'. 
                              $this->rateRequest. '>'; 

        $this->xml_package = '<Package><Service></Service><ZipOrigination> 
                        </ZipOrigination><ZipDestination></ZipDestination> 
                        <Pounds></Pounds><Ounces></Ounces><Container> 
                        </Container><Size></Size></Package>'; 
    } 
}