Web lists-archives.com

Re: Function name must be a string error




On 04.12.2018 at 02:01, Jeffry Killen wrote:

> self::$_proc(/*args*/) // ->  Function name must be a string
If you used the recommended setting for error_reporting during
development, you'd gotten a more useful error notice; something like:

  Notice: Undefined variable: _proc in %s on line %d

The problem is that PHP thinks that $_proc(/*args*/) should be called to
get the name of the property of self, i.e. it basically does:

  $temp = $_proc(/*args*/);
  self::$temp;

This obviously isn't what you've intended.  You can work around that in
PHP 5 by doing something like:

  $temp = self::$_proc;
  $temp(/*args*/);

As of PHP 7.0.0 you can use the following instead (like Enno already wrote):

  (self::$_proc)(/*args*/);

-- 
Christoph M. Becker