Skip to content

Commit ca652aa

Browse files
committed
Fixed bug #78632
I'm going for a very conservative fix here, where the previous logic is restored for the case where an object is passed to method_exists(). We might want to check against EG(scope) instead, but this seems like a safer choice. This means that behavior in PHP 7.4 changes only for method_exists('C', 'privateMethodNotOnC'), which should be sensible.
1 parent 9659562 commit ca652aa

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug #78614 (Does not compile with DTRACE anymore).
77
(tz at FreeBSD dot org)
88
. Fixed bug #78620 (Out of memory error). (cmb, Nikita)
9+
. Fixed bug #78632 (method_exists() in php74 works differently from php73 in
10+
checking priv. methods). (Nikita)
911

1012
- Pcntl:
1113
. Fixed bug #77335 (PHP is preventing SIGALRM from specifying SA_RESTART).

Zend/tests/bug50810.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var_dump($example->propertyBarExists());
4040

4141
?>
4242
--EXPECT--
43-
bool(false)
43+
bool(true)
4444
bool(true)
4545
bool(true)
4646
bool(true)

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,11 @@ ZEND_FUNCTION(method_exists)
13731373
zend_string_release_ex(lcname, 0);
13741374

13751375
if (func) {
1376-
RETURN_BOOL(!(func->common.fn_flags & ZEND_ACC_PRIVATE) || func->common.scope == ce);
1376+
/* Exclude shadow properties when checking a method on a specific class. Include
1377+
* them when checking an object, as method_exists() generally ignores visibility.
1378+
* TODO: Should we use EG(scope) for the object case instead? */
1379+
RETURN_BOOL(Z_TYPE_P(klass) == IS_OBJECT
1380+
|| !(func->common.fn_flags & ZEND_ACC_PRIVATE) || func->common.scope == ce);
13771381
}
13781382

13791383
if (Z_TYPE_P(klass) == IS_OBJECT) {

ext/standard/tests/class_object/method_exists_basic_001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ foreach ($methods as $method) {
5050
echo "Done";
5151
?>
5252
--EXPECT--
53-
---(Using string class name)---
53+
---(Using string class name)---
5454
Does C::inherit_pub exist? bool(true)
5555
Does C::inherit_prot exist? bool(true)
5656
Does C::inherit_priv exist? bool(false)
@@ -68,10 +68,10 @@ Does C::non_existent exist? bool(false)
6868
---(Using object)---
6969
Does C::inherit_pub exist? bool(true)
7070
Does C::inherit_prot exist? bool(true)
71-
Does C::inherit_priv exist? bool(false)
71+
Does C::inherit_priv exist? bool(true)
7272
Does C::inherit_static_pub exist? bool(true)
7373
Does C::inherit_static_prot exist? bool(true)
74-
Does C::inherit_static_priv exist? bool(false)
74+
Does C::inherit_static_priv exist? bool(true)
7575
Does C::pub exist? bool(true)
7676
Does C::prot exist? bool(true)
7777
Does C::priv exist? bool(true)

0 commit comments

Comments
 (0)