Jump to content

Class member assignment error


unkwntech

Recommended Posts

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

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();
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.