0

I know this is a very generic error, but I am getting a:

( ! ) Parse error: syntax error, unexpected 'openFile' (T_STRING), expecting variable (T_VARIABLE) in //file on line 13

and here is my relavent code:

class Dictionary{

    private $fileHandler;

    const FILESRC = 'resources/dictionary.txt';

    //Just in case I want to extend class to write dictionary;
    const FILEMODE = 'r';

    const MAXLINES = 1024;

    protected openFile(){
        if(!isset($this->$fileHandler)) 
            $this->$fileHandler = fopen(self::FILESRC, self::FILEMODE); 
    }
}

I can't seem to find solutions, tryed some of the simular problems, but the error is too generic I also had a look over at PHP Parse/Syntax Errors; and How to solve them?

Any suggestions would be of much needed help.

Thanks in advance

Community
  • 1
  • 1
  • 2
    Instead of `protected openFile()` you need `protected function openFile()`, I think you should make use of an IDE with type hinting and syntax checking. Also see @RiggsFolly comment about the fileHandler. – Perry Jul 20 '16 at 23:17
  • 2
    And `$this->$fileHandler` should be `$this->fileHandler` – RiggsFolly Jul 20 '16 at 23:17
  • 1
    And some sensible code indentation would help with readability and **debugability** – RiggsFolly Jul 20 '16 at 23:18

0 Answers0