0
  • I don't want to declare static variables or class constants because in the example $v is prone to change.
  • I don't want to pass through return statement.

Is there a mechanism for such a behavior to be implemented ?


enter image description here

vdegenne
  • 12,272
  • 14
  • 80
  • 106
  • If the parent method doesn't return the value, then no, there's no way to access `$v` from the parent in the above example. If you want a value to be accessible outside a method, then make it a class property. It's what they are for. – M. Eriksson Jul 24 '17 at 11:56
  • In short: no. Either you `return` the value, or you make it an instance property (`$this->v`). – deceze Jul 24 '17 at 11:57
  • `$v` does not exist outside of the `call()` function. It is a local variable. Read about [variables scope](http://php.net/manual/en/language.variables.scope.php). – axiac Jul 24 '17 at 12:02

0 Answers0