From 9c710b1d11bb200d75d295cb78143455403315a1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 7 Oct 2020 11:34:14 +0200 Subject: [PATCH] Support "static" type in gen_stub --- build/gen_stub.php | 9 +++++++++ ext/zend_test/test.c | 17 +++++++++++------ ext/zend_test/test.stub.php | 2 ++ ext/zend_test/test_arginfo.h | 7 ++++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 41542cf97b..f3e84c27fd 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -111,6 +111,11 @@ class SimpleType { public static function fromNode(Node $node) { if ($node instanceof Node\Name) { + if ($node->toLowerString() === 'static') { + // PHP internally considers "static" a builtin type. + return new SimpleType($node->toString(), true); + } + assert($node->isFullyQualified()); return new SimpleType($node->toString(), false); } @@ -147,6 +152,8 @@ class SimpleType { return "IS_ITERABLE"; case "mixed": return "IS_MIXED"; + case "static": + return "IS_STATIC"; default: throw new Exception("Not implemented: $this->name"); } @@ -175,6 +182,8 @@ class SimpleType { return "MAY_BE_CALLABLE"; case "mixed": return "MAY_BE_ANY"; + case "static": + return "MAY_BE_STATIC"; default: throw new Exception("Not implemented: $this->name"); } diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 13781e32be..7871d9dc7c 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -292,21 +292,26 @@ void zend_attribute_validate_zendtestattribute(zend_attribute *attr, uint32_t ta } } -static ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ { +static ZEND_METHOD(_ZendTestClass, __toString) { + ZEND_PARSE_PARAMETERS_NONE(); RETURN_EMPTY_STRING(); } -/* }}} */ /* Internal function returns bool, we return int. */ -static ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ { +static ZEND_METHOD(_ZendTestClass, is_object) { + ZEND_PARSE_PARAMETERS_NONE(); RETURN_LONG(42); } -/* }}} */ -static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ { +static ZEND_METHOD(_ZendTestClass, returnsStatic) { + ZEND_PARSE_PARAMETERS_NONE(); + object_init_ex(return_value, zend_get_called_scope(execute_data)); +} + +static ZEND_METHOD(_ZendTestTrait, testMethod) { + ZEND_PARSE_PARAMETERS_NONE(); RETURN_TRUE; } -/* }}} */ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("zend_test.observer.enabled", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_enabled, zend_zend_test_globals, zend_test_globals) diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index 96e7b56921..e07b5708c9 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -7,6 +7,8 @@ class _ZendTestClass { /** @deprecated */ public function __toString(): string {} + + public function returnsStatic(): static {} } trait _ZendTestTrait { diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h index 80e89c6fe0..1cae7420e5 100644 --- a/ext/zend_test/test_arginfo.h +++ b/ext/zend_test/test_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 1aa8e876ff9efb99c61603216eed267b0d225221 */ + * Stub hash: 2d871bb7fda01594bb46f53bca64323424db4709 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -57,6 +57,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass___toString, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_returnsStatic, 0, 0, IS_STATIC, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestTrait_testMethod, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -76,6 +79,7 @@ static ZEND_FUNCTION(zend_string_or_stdclass_or_null); static ZEND_FUNCTION(zend_iterable); static ZEND_METHOD(_ZendTestClass, is_object); static ZEND_METHOD(_ZendTestClass, __toString); +static ZEND_METHOD(_ZendTestClass, returnsStatic); static ZEND_METHOD(_ZendTestTrait, testMethod); @@ -100,6 +104,7 @@ static const zend_function_entry ext_functions[] = { static const zend_function_entry class__ZendTestClass_methods[] = { ZEND_ME(_ZendTestClass, is_object, arginfo_class__ZendTestClass_is_object, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(_ZendTestClass, __toString, arginfo_class__ZendTestClass___toString, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) + ZEND_ME(_ZendTestClass, returnsStatic, arginfo_class__ZendTestClass_returnsStatic, ZEND_ACC_PUBLIC) ZEND_FE_END }; -- 2.40.0