While

    <?php
    class a {
        public function b() {
            $f = function () {
                $this->c();
            };
        }
    }

 compiles as expected with PHP 5.4, the following

    <?php
    class a {
        public function b() {
            $f = function () use ($this) {
                $this->c();
            };
        }
    }

 results in

   Fatal error: Cannot use $this as lexical variable in ...

 This is because

    void zend_do_fetch_lexical_variable(znode *varname,
    zend_bool is_ref TSRMLS_DC) /* {{{ */
    {
        znode value;

        if (Z_STRLEN(varname->u.constant) == sizeof("this") - 1 &&
            memcmp(Z_STRVAL(varname->u.constant), "this",
            sizeof("this") - 1) == 0) {
            zend_error(E_COMPILE_ERROR, "Cannot use $this as lexical
            variable");
            return;
        }

 is still in zend_compile.c. IIRC, this code was added in PHP 5.3 to
 prevent $this from being used as a lexical variable. It should no
 longer be required in PHP 5.4. Right?

--
Sebastian Bergmann                    Co-Founder and Principal Consultant
http://sebastian-bergmann.de/                           http://thePHP.cc/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to