]> granicus.if.org Git - php/commitdiff
Use C zpp for get_class_vars()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 11:05:05 +0000 (13:05 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 11:05:05 +0000 (13:05 +0200)
Zend/tests/get_class_vars_001.phpt
Zend/zend_builtin_functions.c
Zend/zend_builtin_functions.stub.php
Zend/zend_builtin_functions_arginfo.h
ext/opcache/Optimizer/zend_func_info.c

index a5939ccd5f1d0d2cb8e489138754dca4875946c7..84f502610ecaffd3efbed00f94d5a41227bdb7ff 100644 (file)
@@ -19,6 +19,12 @@ class B extends A {
 var_dump(get_class_vars('A'));
 var_dump(get_class_vars('B'));
 
+try {
+    get_class_vars("Unknown");
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
+
 ?>
 --EXPECT--
 array(1) {
@@ -31,3 +37,4 @@ array(2) {
   ["aa"]=>
   int(4)
 }
+get_class_vars(): Argument #1 ($class) must be a valid class name, Unknown given
index fbc7d1332907ccd0ede2d5aac5fe2314b9011223..ac652b3b8a0097f5f58e613c43d75ace83ea87a2 100644 (file)
@@ -747,27 +747,22 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s
 /* {{{ Returns an array of default properties of the class. */
 ZEND_FUNCTION(get_class_vars)
 {
-       zend_string *class_name;
-       zend_class_entry *ce, *scope;
+       zend_class_entry *ce = NULL, *scope;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "C", &ce) == FAILURE) {
                RETURN_THROWS();
        }
 
-       ce = zend_lookup_class(class_name);
-       if (!ce) {
-               RETURN_FALSE;
-       } else {
-               array_init(return_value);
-               if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
-                       if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
-                               return;
-                       }
+       array_init(return_value);
+       if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
+               if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
+                       return;
                }
-               scope = zend_get_executed_scope();
-               add_class_vars(scope, ce, 0, return_value);
-               add_class_vars(scope, ce, 1, return_value);
        }
+
+       scope = zend_get_executed_scope();
+       add_class_vars(scope, ce, 0, return_value);
+       add_class_vars(scope, ce, 1, return_value);
 }
 /* }}} */
 
index 5d5ebcde14a1fe61fe2814f5ea8dbe98755a6338..eaf2ac490a42247a9d5fd9ab68bccf593e2feeb9 100644 (file)
@@ -39,7 +39,7 @@ function is_subclass_of(mixed $object_or_class, string $class, bool $allow_strin
 /** @param object|string $object_or_class */
 function is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool {}
 
-function get_class_vars(string $class): array|false {}
+function get_class_vars(string $class): array {}
 
 function get_object_vars(object $object): array {}
 
index 4b551e3d59c48398e923448f39b56620300575e0..d10e2c3d68824f3888dea1f6256f82aba57b237e 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 1f644f72600eddbbb01a4c3912a2c9c5fe12188e */
+ * Stub hash: fed3b572fbcae7bda87efc377b56e027da12b511 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
 ZEND_END_ARG_INFO()
@@ -69,7 +69,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_is_a, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, allow_string, _IS_BOOL, 0, "false")
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_class_vars, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_class_vars, 0, 1, IS_ARRAY, 0)
        ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
index e3a258802875bd29b7913257e80f0923aaf8f3c1..936e8a8915ff48f49b3183b65521cee0474cfe22 100644 (file)
@@ -97,7 +97,7 @@ static const func_info_t func_infos[] = {
        F1("zend_version",            MAY_BE_STRING),
        FN("func_get_arg",            UNKNOWN_INFO),
        FN("func_get_args",           MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_ANY),
-       F1("get_class_vars",          MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
+       F1("get_class_vars",          MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
        F1("get_class_methods",       MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
        F1("get_included_files",      MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
        FN("set_error_handler",       MAY_BE_NULL | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_OBJECT | MAY_BE_OBJECT),