Skip to content

Commit 3f3c1ad

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Similar problem (#79022) also exists in Interfaces Fixed bug #79022 (class_exists returns True for classes that are not ready to be used)
2 parents 1e53769 + f09b958 commit 3f3c1ad

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

Zend/tests/bug79022.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Bug #79022 (class_exists returns True for classes that are not ready to be used)
3+
--FILE--
4+
<?php
5+
function my_autoloader($class) {
6+
if (class_exists('Foo', 0)) {
7+
new Foo();
8+
}
9+
if ($class == 'Foo') {
10+
eval("class Foo extends Bar{}");
11+
}
12+
13+
if ($class == 'Bar') {
14+
eval("class Bar {}");
15+
}
16+
17+
if ($class == 'Dummy') {
18+
eval ("class Dummy implements iFoo {}");
19+
}
20+
21+
22+
if (interface_exists('iFoo', 0)) {
23+
new Dummy();
24+
}
25+
if ($class == 'iFoo') {
26+
eval ("interface iFoo extends iBar {}");
27+
}
28+
29+
if ($class == 'iBar') {
30+
eval ("interface iBar {}");
31+
}
32+
}
33+
spl_autoload_register('my_autoloader');
34+
new Foo();
35+
new Dummy();
36+
echo "okey";
37+
?>
38+
--EXPECT--
39+
okey

Zend/zend_builtin_functions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, in
12481248
}
12491249

12501250
if (ce) {
1251-
RETURN_BOOL((flags == 0 || (ce->ce_flags & flags)) && !(ce->ce_flags & skip_flags));
1251+
RETURN_BOOL(((ce->ce_flags & flags) == flags) && !(ce->ce_flags & skip_flags));
12521252
} else {
12531253
RETURN_FALSE;
12541254
}
@@ -1259,15 +1259,15 @@ static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, in
12591259
Checks if the class exists */
12601260
ZEND_FUNCTION(class_exists)
12611261
{
1262-
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
1262+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
12631263
}
12641264
/* }}} */
12651265

12661266
/* {{{ proto bool interface_exists(string classname [, bool autoload])
12671267
Checks if the class exists */
12681268
ZEND_FUNCTION(interface_exists)
12691269
{
1270-
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE, 0);
1270+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED|ZEND_ACC_INTERFACE, 0);
12711271
}
12721272
/* }}} */
12731273

0 commit comments

Comments
 (0)