Concatenated string disallowed in class properties?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Concatenated string disallowed in class properties?

Post by jraede »

I'm pretty sure that I don't have an error in my syntax, so it must be that PHP doesn't allow concatenated strings in property definitions. Is this the case?

This is what I have...

Code: Select all

class slt_handler_form_login extends slt_handler_form {
	protected $form_redirect_failure = SLT_ROOT_URL.'/login/';
	protected $form_redirect_success = SLT_ROOT_URL . '/user/';
       
       ...etc
And it says "Parse error: syntax error, unexpected '.', expecting ',' or ';'", referring to the line with $form_redirect_failure. I made sure that the constant is defined by commenting out the deviant lines and echoing it out in the __construct() method, so that's not the issue.

Since it seems like this is not allowed, is there a way around it? I'd rather not have to prepend SLT_ROOT_URL everywhere the properties are used.

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Concatenated string disallowed in class properties?

Post by John Cartwright »

You cannot define anything dynamic in the property definitions. As you mentioned, you need to do

Code: Select all

class slt_handler_form_login extends slt_handler_form {
        protected $form_redirect_failure;
        protected $form_redirect_success;

        public function __construct() {
                $this->form_redirect_failure = SLT_ROOT_URL.'/login/';
                $this->form_redirect_success = SLT_ROOT_URL . '/user/';
        }
}
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Concatenated string disallowed in class properties?

Post by jraede »

Gotcha. I actually just realized I had done that with other form controllers, so I guess I thought of that already :-)
Post Reply