0

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>';
    }
}
2
  • Please include the error text in your post. Is this wrapped in <?php and ?> tags? Commented Apr 19, 2012 at 21:58
  • I have the opening <?php tag but I don't close it. I have read it is better to leave it open? But Mark's answer below fixed it for me. Commented Apr 19, 2012 at 22:01

1 Answer 1

3

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>'; 
    } 
} 
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, that fixed my problem! I am trying to learn OOP and this all new to me.
hows public adequately represented with protected? And if you want to hide, suggest private and not protected.
@hakre - I could have left them as public, it's just personal habit (I'm a strong believer in getters/setters to control access to properties, but in allowing properties to be redeclared within the inheritance hierarchy
@MarkBaker: But if you like getters / setters, why do you make it protected and not private?
@hakre - comments against an answer isn't a good medium for the relative merits of different visibilities... but the simple answer is that private properties can't be redeclared in a child class
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.