Search code examples
phpclassvariablesphp4

PHP 4 - variables inside class


I have a class like

class blah extends blahblah{

  private $variable = '5';

  function somefunction(){
    echo $variable;
  }
}

this works in php 5, but not in php 4. I get a error:

Parse error: parse error, unexpected
T_VARIABLE, expecting T_OLD_FUNCTION
or T_FUNCTION or T_VA....

I also tried with public and static. Same error.

How can I add a variable inside that class that I can access from all class functions?


Solution

  • private is not a valid keyword in PHP 4 change it to var $variable = '5'; also the function is wrong it should be...

    class blah extends blahblah{
    
      var $variable = '5';
    
      function somefunction(){
        echo $this->variable;
      }
    }