PHP 4 - variables inside a 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 an error:

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

I also tried with publicand static. The same error.

How to add a variable inside this class that I can access from all the functions of the class?

+3
source share
2 answers

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

class blah extends blahblah{

  var $variable = '5';

  function somefunction(){
    echo $this->variable;
  }
}
+8
source

In PHP4, member variables are declared using var:

var $variable = '5';

But you still have to access it through $this->variablein your function (I think I'm not very familiar with PHP4).

, , ! PHP4 "" - , .

: , , PHP4.

+8

Source: https://habr.com/ru/post/1786540/


All Articles