Bug #78632 [Asn->Csd]: method_exists() in php74 works differently from php73 in checking priv. methods
| From: | nikic@php.net | Date: | Fri, 04 Oct 2019 10:42:27 +0000 |
| Subject: | Bug #78632 [Asn->Csd]: method_exists() in php74 works differently from php73 in checking priv. methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223059@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78632&edit=1
ID: 78632
Updated by: nikic@php.net
Reported by: work at iskida dot com
Summary: method_exists() in php74 works differently from
php73 in checking priv. methods
-Status: Assigned
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: Fedora 30
PHP Version: 7.4.0RC3
Assigned To: nikic
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=ca652aafa8d293ac46a171b6b1326431aa13600c
Log: Fixed bug #78632
Previous Comments:
------------------------------------------------------------------------
[2019-10-04 08:25:20] cmb@php.net
Hmm, this looks like an unintended side-effect of commit
6255308[1]. Could you please have a look, Nikita?
[1] <http://git.php.net/?p=php-src.git;a=commit;h=6255308624a2a6bdbfa8581b9b920a8d180e458f>
------------------------------------------------------------------------
[2019-10-04 02:18:31] work at iskida dot com
Description:
------------
method_exists() in php74 works differently from php73 in checking private methods
versions used
php73 PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
php74 PHP 7.4.0RC3 (cli) (built: Oct 1 2019 08:30:29) ( NTS )
Operating system
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description: Fedora release 30 (Thirty)
Test script:
---------------
class Base {
public function __get($k) {
$m = '_get_'.$k;
if (!method_exists($this, $m)) throw new \Exception('no-property:'.$k);
return $this->$m();
}
private function _get_a() { return 'a'; }
}
class Test extends Base {}
$x = new Test;
echo $x->a;
//php74 : PHP Fatal error: Uncaught Exception: no-property-a in test.php
//php73 : prints a
Expected result:
----------------
I expect both php73 and php74 printing "a"
note that _get_a() method is properly executed (when no check with "method_exists" is
done) both by php73 and php74.
class Base {
public function __get($k) {
$m = '_get_'.$k;
//NO check
return $this->$m();
}
private function _get_a() { return 'a'; }
}
class Test extends Base {}
$x = new Test;
echo $x->a;
//prints "a" both in php73 and php74
***So I expect that method_exists() in php74 should return (bool) true as in php73...because the
method "EXISTS" is reached and executed***, or, for consinstency, php74 should throw a
"PHP Fatal error: Uncaught Error: Call to private method Test::_get_a()" when accessing
_get_a() method. (But a huge amount of codebase is involved with no doubt)
Actual result:
--------------
php74 : PHP Fatal error: Uncaught Exception: no-property-a in test.php
php73 : prints a
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78632&edit=1