unkwntech Posted March 4, 2009 Share Posted March 4, 2009 I have a class with the following assignments /** * The full path to where the error log should be stored */ var $errorLogPath = '/var/www/mydomail.tld/'; /** * The name of the error log */ var $errorFilename = 'error.log'; /*... */ /** * We're going to simplify the variable for the error log so we don't have to concat it later. */ var $errorLog = $this->errorLogPath . $this->errorFilename; // THIS IS LINE 50 I'm not sure why but I am getting Parsing Error: D:\PHPSO\config.php line 50 - syntax error, unexpected T_VARIABLE Link to comment https://forums.phpfreaks.com/topic/147916-class-member-assignment-error/ Share on other sites More sharing options...
phpdragon Posted March 4, 2009 Share Posted March 4, 2009 shouldnt errorLogPath and errorFilename on line 50 have a $ infront as they are variables Link to comment https://forums.phpfreaks.com/topic/147916-class-member-assignment-error/#findComment-776333 Share on other sites More sharing options...
unkwntech Posted March 4, 2009 Author Share Posted March 4, 2009 No because they are members of the "this" object so $this->varName is a reference to the variable in the class. Link to comment https://forums.phpfreaks.com/topic/147916-class-member-assignment-error/#findComment-776377 Share on other sites More sharing options...
rhodesa Posted March 4, 2009 Share Posted March 4, 2009 you can't reference $this when declaring a paramater. in the declaration, those parameters live outside the context of an instance. either use the variables separately or use a method in the class instead: <?php class className { var $errorLogPath = '/var/www/mydomail.tld/'; var $errorFilename = 'error.log'; function getErrorLogPath ( ) { return $this->errorLogPath . $this->errorFilename; } function doError ( ) { //Either use the variables separately $errorPath = $this->errorLogPath . $this->errorFilename; //Or with the function $errorPath = $this->getErrorLogPath(); } } ?> Link to comment https://forums.phpfreaks.com/topic/147916-class-member-assignment-error/#findComment-776385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.