Page 1 of 1

Constant concatenation

Posted: Wed Dec 17, 2003 1:46 am
by pascalz
if I make this :

Code: Select all

define("MYCONST","MYCONSTVALUE",TRUE);
and in a class I declare a variable like this :

Code: Select all

var $MyVar = MYCONST." something";
I have an error message !
Parse error: parse error, unexpected '.', expecting ',' or ';' in ....

Constants seems dont work in concatenation...
if I do :

Code: Select all

var $MyVar = MYCONST; // It's working !
Is there a way to do this ?

Posted: Wed Dec 17, 2003 2:04 am
by m3mn0n

Code: Select all

<?php
$const = MYCONST;
$MyVar = $const." something";
?>
How is that?

Posted: Wed Dec 17, 2003 2:11 am
by pascalz
Sami wrote:

Code: Select all

<?php
$const = MYCONST;
$MyVar = $const." something";
?>
How is that?
I'm in a class, i try this :

Code: Select all

var $const = MYCONST;
var $MyVar = $this->const." something";
I've now:
Parse error: parse error, unexpected T_VARIABLE in ...

Posted: Wed Dec 17, 2003 2:37 am
by m3mn0n
heh, my brain isn't functioning right, right now so I'll get back to you on that later today if nobody else helps you by then. Image

Posted: Wed Dec 17, 2003 3:25 am
by aquila125
try removing the $this-> if you'r not in a method, I don't think you need it...

Posted: Wed Dec 17, 2003 4:09 am
by pascalz
aquila125 wrote:try removing the $this-> if you'r not in a method, I don't think you need it...
I've the same error :?

Posted: Wed Dec 17, 2003 10:47 am
by Weirdan
You can't have non-constant initializers in class. Seems like all expressions are treated as non-constant in PHP. So move the assignment to constructor.