summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2019-12-24 14:21:52 +0800
committerXinchen Hui <laruence@gmail.com>2019-12-24 14:21:52 +0800
commit3f3c1ad848cc3c0e94c8586bcd84bf3386a2d0d3 (patch)
treef477d9132d2cfbcba00fd695be83ad0c990dda34
parent1e53769d82dadd2ea1aa05aa5397f192f7c33c4d (diff)
parentf09b958e90afc0458a30a2c775abc2525827e7ac (diff)
downloadphp-git-3f3c1ad848cc3c0e94c8586bcd84bf3386a2d0d3.tar.gz
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)
-rw-r--r--Zend/tests/bug79022.phpt39
-rw-r--r--Zend/zend_builtin_functions.c6
2 files changed, 42 insertions, 3 deletions
diff --git a/Zend/tests/bug79022.phpt b/Zend/tests/bug79022.phpt
new file mode 100644
index 0000000000..0657b20355
--- /dev/null
+++ b/Zend/tests/bug79022.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug #79022 (class_exists returns True for classes that are not ready to be used)
+--FILE--
+<?php
+function my_autoloader($class) {
+ if (class_exists('Foo', 0)) {
+ new Foo();
+ }
+ if ($class == 'Foo') {
+ eval("class Foo extends Bar{}");
+ }
+
+ if ($class == 'Bar') {
+ eval("class Bar {}");
+ }
+
+ if ($class == 'Dummy') {
+ eval ("class Dummy implements iFoo {}");
+ }
+
+
+ if (interface_exists('iFoo', 0)) {
+ new Dummy();
+ }
+ if ($class == 'iFoo') {
+ eval ("interface iFoo extends iBar {}");
+ }
+
+ if ($class == 'iBar') {
+ eval ("interface iBar {}");
+ }
+}
+spl_autoload_register('my_autoloader');
+new Foo();
+new Dummy();
+echo "okey";
+?>
+--EXPECT--
+okey
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 2832fb3e0a..b24d620c71 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1248,7 +1248,7 @@ static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, in
}
if (ce) {
- RETURN_BOOL((flags == 0 || (ce->ce_flags & flags)) && !(ce->ce_flags & skip_flags));
+ RETURN_BOOL(((ce->ce_flags & flags) == flags) && !(ce->ce_flags & skip_flags));
} else {
RETURN_FALSE;
}
@@ -1259,7 +1259,7 @@ static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, in
Checks if the class exists */
ZEND_FUNCTION(class_exists)
{
- class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
+ class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
}
/* }}} */
@@ -1267,7 +1267,7 @@ ZEND_FUNCTION(class_exists)
Checks if the class exists */
ZEND_FUNCTION(interface_exists)
{
- class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE, 0);
+ class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED|ZEND_ACC_INTERFACE, 0);
}
/* }}} */