Skip to content

Commit 9c710b1

Browse files
committed
Support "static" type in gen_stub
1 parent c11191e commit 9c710b1

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

build/gen_stub.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public function __construct(string $name, bool $isBuiltin) {
111111

112112
public static function fromNode(Node $node) {
113113
if ($node instanceof Node\Name) {
114+
if ($node->toLowerString() === 'static') {
115+
// PHP internally considers "static" a builtin type.
116+
return new SimpleType($node->toString(), true);
117+
}
118+
114119
assert($node->isFullyQualified());
115120
return new SimpleType($node->toString(), false);
116121
}
@@ -147,6 +152,8 @@ public function toTypeCode() {
147152
return "IS_ITERABLE";
148153
case "mixed":
149154
return "IS_MIXED";
155+
case "static":
156+
return "IS_STATIC";
150157
default:
151158
throw new Exception("Not implemented: $this->name");
152159
}
@@ -175,6 +182,8 @@ public function toTypeMask() {
175182
return "MAY_BE_CALLABLE";
176183
case "mixed":
177184
return "MAY_BE_ANY";
185+
case "static":
186+
return "MAY_BE_STATIC";
178187
default:
179188
throw new Exception("Not implemented: $this->name");
180189
}

ext/zend_test/test.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,26 @@ void zend_attribute_validate_zendtestattribute(zend_attribute *attr, uint32_t ta
292292
}
293293
}
294294

295-
static ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ {
295+
static ZEND_METHOD(_ZendTestClass, __toString) {
296+
ZEND_PARSE_PARAMETERS_NONE();
296297
RETURN_EMPTY_STRING();
297298
}
298-
/* }}} */
299299

300300
/* Internal function returns bool, we return int. */
301-
static ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ {
301+
static ZEND_METHOD(_ZendTestClass, is_object) {
302+
ZEND_PARSE_PARAMETERS_NONE();
302303
RETURN_LONG(42);
303304
}
304-
/* }}} */
305305

306-
static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
306+
static ZEND_METHOD(_ZendTestClass, returnsStatic) {
307+
ZEND_PARSE_PARAMETERS_NONE();
308+
object_init_ex(return_value, zend_get_called_scope(execute_data));
309+
}
310+
311+
static ZEND_METHOD(_ZendTestTrait, testMethod) {
312+
ZEND_PARSE_PARAMETERS_NONE();
307313
RETURN_TRUE;
308314
}
309-
/* }}} */
310315

311316
PHP_INI_BEGIN()
312317
STD_PHP_INI_BOOLEAN("zend_test.observer.enabled", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_enabled, zend_zend_test_globals, zend_test_globals)

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public static function is_object(): int {}
77

88
/** @deprecated */
99
public function __toString(): string {}
10+
11+
public function returnsStatic(): static {}
1012
}
1113

1214
trait _ZendTestTrait {

ext/zend_test/test_arginfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1aa8e876ff9efb99c61603216eed267b0d225221 */
2+
* Stub hash: 2d871bb7fda01594bb46f53bca64323424db4709 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -57,6 +57,9 @@ ZEND_END_ARG_INFO()
5757
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass___toString, 0, 0, IS_STRING, 0)
5858
ZEND_END_ARG_INFO()
5959

60+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_returnsStatic, 0, 0, IS_STATIC, 0)
61+
ZEND_END_ARG_INFO()
62+
6063
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestTrait_testMethod, 0, 0, _IS_BOOL, 0)
6164
ZEND_END_ARG_INFO()
6265

@@ -76,6 +79,7 @@ static ZEND_FUNCTION(zend_string_or_stdclass_or_null);
7679
static ZEND_FUNCTION(zend_iterable);
7780
static ZEND_METHOD(_ZendTestClass, is_object);
7881
static ZEND_METHOD(_ZendTestClass, __toString);
82+
static ZEND_METHOD(_ZendTestClass, returnsStatic);
7983
static ZEND_METHOD(_ZendTestTrait, testMethod);
8084

8185

@@ -100,6 +104,7 @@ static const zend_function_entry ext_functions[] = {
100104
static const zend_function_entry class__ZendTestClass_methods[] = {
101105
ZEND_ME(_ZendTestClass, is_object, arginfo_class__ZendTestClass_is_object, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
102106
ZEND_ME(_ZendTestClass, __toString, arginfo_class__ZendTestClass___toString, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
107+
ZEND_ME(_ZendTestClass, returnsStatic, arginfo_class__ZendTestClass_returnsStatic, ZEND_ACC_PUBLIC)
103108
ZEND_FE_END
104109
};
105110

0 commit comments

Comments
 (0)