php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78632 method_exists() in php74 works differently from php73 in checking priv. methods
Submitted: 2019-10-04 02:18 UTC Modified: 2019-10-04 08:25 UTC
From: work at iskida dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.4.0RC3 OS: Fedora 30
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: work at iskida dot com
New email:
PHP Version: OS:

 

 [2019-10-04 02:18 UTC] 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 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-04 08:25 UTC] cmb@php.net
-Assigned To: +Assigned To: nikic
 [2019-10-04 08:25 UTC] 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 10:42 UTC] nikic@php.net
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
 [2019-10-04 10:42 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-10-04 10:43 UTC] nikic@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC