...

View Full Version : class variable not letting me use fullstop



mike182uk
01-23-2010, 03:51 PM
hi there, i'am having a problem with using the the fullstop to concat 2 stings in a class variable.



define("TEST", "hello");

class myclass
{
var $myvar = TEST . "world";
}


is there any reason why the above wouldnt work? if so how would i get around it?

i get an error but i am using an IIS server and for some reason it wont let me turn on php errors. sorry.

abduraooft
01-23-2010, 04:16 PM
You can't use an expression or return value of a function to a class member while decalration. You'd need to move that code into constructor, like

class myclass
{
var $myvar;
function __construct(){
$this->myvar=TEST . "world";
}
}

JAY6390
01-23-2010, 04:24 PM
This doesn't work no matter what server you use. You can't concatenate strings when defining properties of a class

mike182uk
01-23-2010, 04:39 PM
hey abduraooft thanks alot for that, i thought i was just making a syntax error, i didnt even know about the constructor. anyways thanks alot that worked great! i'll go and read up on constructors :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum