Why can I not use $this as a lexical variable in PHP 5.5.4?

后端 未结 8 1639
再見小時候
再見小時候 2020-12-04 01:12
$ php --version
PHP 5.5.4 (cli) (built: Sep 19 2013 17:10:06) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
         


        
8条回答
  •  感动是毒
    2020-12-04 01:50

    It may be a bug, but there is no sense in explicit binding $this to a function anyway as it is automatically bound:

    PHP documentation says

    As of PHP 5.4.0, when declared in the context of a class, the current class is automatically bound to it, making $this available inside of the function's scope.

    Thus, fatal error is thrown in today's version of PHP:

    From PHP 7.1, these variables must not include superglobals, $this, or variables with the same name as a parameter.

提交回复
热议问题