Bug #78770 [Opn->Csd]: Incorrect callability check inside internal methods

From: Date: Fri, 14 Aug 2020 08:24:12 +0000
Subject: Bug #78770 [Opn->Csd]: Incorrect callability check inside internal methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228588@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78770&edit=1

 ID:                 78770
 Updated by:         nikic@php.net
 Reported by:        nikic@php.net
 Summary:            Incorrect callability check inside internal methods
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        7.2.24
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=befe10fd21c82e82d8621558b7998424ab6d2c6d
Log: Fix bug #78770


Previous Comments:
------------------------------------------------------------------------
[2019-11-01 15:53:47] nikic@php.net

Description:
------------
Due to the way zend_get_executed_scope() works, callability checks inside internal *methods* work
different from internal *functions*. They will use the scope of the method itself, rather than the
scope of the calling userland method.

The attached example uses an IntlChar method with "f" parameter to show the problem.

Test script:
---------------
<?php
  
class Test {
    public function method() {
        IntlChar::enumCharTypes([$this, 'privateMethod']);
    }

    private function privateMethod($start, $end, $name) {
    }
}

(new Test)->method();

Actual result:
--------------
Fatal error: Uncaught TypeError: IntlChar::enumCharTypes() expects parameter 1 to be a valid
callback, cannot access private method Test::privateMethod() in /home/nikic/php-src/t074.php:5
Stack trace:
#0 /home/nikic/php-src/t074.php(5): IntlChar::enumCharTypes(Array)
#1 /home/nikic/php-src/t074.php(12): Test->method()
#2 {main}
  thrown in /home/nikic/php-src/t074.php on line 5



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78770&edit=1


Thread (2 messages)

« previous php.bugs (#228588) next »