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
pascalz
Forum Newbie
Posts: 3 Joined: Wed Dec 17, 2003 1:46 am
Location: France
Contact:
Post
by pascalz » Wed Dec 17, 2003 1:46 am
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 ?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Wed Dec 17, 2003 2:04 am
Code: Select all
<?php
$const = MYCONST;
$MyVar = $const." something";
?>
How is that?
pascalz
Forum Newbie
Posts: 3 Joined: Wed Dec 17, 2003 1:46 am
Location: France
Contact:
Post
by pascalz » Wed Dec 17, 2003 2:11 am
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 ...
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Wed Dec 17, 2003 2:37 am
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.
aquila125
Forum Commoner
Posts: 96 Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium
Post
by aquila125 » Wed Dec 17, 2003 3:25 am
try removing the $this-> if you'r not in a method, I don't think you need it...
pascalz
Forum Newbie
Posts: 3 Joined: Wed Dec 17, 2003 1:46 am
Location: France
Contact:
Post
by pascalz » Wed Dec 17, 2003 4:09 am
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
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Dec 17, 2003 10:47 am
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.