Bead
Bead

Reputation: 363

Class constructor error with declarations

I am getting errors with this, NetBeans is telling me it was expecting something on the last line of the $xml_package declaration. Any ideas what I am missing?

Thank you.

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>';
    }
}

Upvotes: 0

Views: 55

Answers (1)

Mark Baker
Mark Baker

Reputation: 212522

That's because you're declaring your properties in the constructor itself, not in the class

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>'; 
    } 
} 

Upvotes: 3

Related Questions