Skip to content

Commit f7fbc63

Browse files
committed
Add more precise type info for stubs
Closes GH-6005
1 parent 1c56b40 commit f7fbc63

File tree

63 files changed

+515
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+515
-635
lines changed

Zend/zend_API.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,9 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
16341634
#define Z_PARAM_PATH_STR(dest) \
16351635
Z_PARAM_PATH_STR_EX(dest, 0, 0)
16361636

1637+
#define Z_PARAM_PATH_STR_OR_NULL(dest) \
1638+
Z_PARAM_PATH_STR_EX(dest, 1, 0)
1639+
16371640
/* old "r" */
16381641
#define Z_PARAM_RESOURCE_EX2(dest, check_null, deref, separate) \
16391642
Z_PARAM_PROLOGUE(deref, separate); \

Zend/zend_weakrefs.stub.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ final class WeakMap implements ArrayAccess, Countable, IteratorAggregate
1515
{
1616
/**
1717
* @param object $object
18-
* @return mixed
1918
*/
20-
public function offsetGet($object) {}
19+
public function offsetGet($object): mixed {}
2120

22-
/**
23-
* @param object $object
24-
* @param mixed $value
25-
*/
26-
public function offsetSet($object, $value): void {}
21+
/** @param object $object */
22+
public function offsetSet($object, mixed $value): void {}
2723

2824
/** @param object $object */
2925
public function offsetExists($object): bool {}

Zend/zend_weakrefs_arginfo.h

Lines changed: 3 additions & 3 deletions
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: 8a90ffe614346c65d312bc5061fd304056b5640a */
2+
* Stub hash: 0569bc7e10a1ec15a3a9eec481da27b647eb1d1d */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_WeakReference___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -11,13 +11,13 @@ ZEND_END_ARG_INFO()
1111
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakReference_get, 0, 0, IS_OBJECT, 1)
1212
ZEND_END_ARG_INFO()
1313

14-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_WeakMap_offsetGet, 0, 0, 1)
14+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetGet, 0, 1, IS_MIXED, 0)
1515
ZEND_ARG_INFO(0, object)
1616
ZEND_END_ARG_INFO()
1717

1818
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetSet, 0, 2, IS_VOID, 0)
1919
ZEND_ARG_INFO(0, object)
20-
ZEND_ARG_INFO(0, value)
20+
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
2121
ZEND_END_ARG_INFO()
2222

2323
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_WeakMap_offsetExists, 0, 1, _IS_BOOL, 0)

ext/com_dotnet/com_com.c

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
PHP_METHOD(com, __construct)
3030
{
3131
zval *object = getThis();
32-
zval *server_params = NULL;
32+
zend_string *server_name = NULL;
33+
HashTable *server_params = NULL;
3334
php_com_dotnet_object *obj;
3435
char *module_name, *typelib_name = NULL;
3536
size_t module_name_len = 0, typelib_name_len = 0;
36-
zend_string *server_name = NULL, *user_name = NULL, *password = NULL, *domain_name = NULL;
37+
zend_string *user_name = NULL, *password = NULL, *domain_name = NULL;
3738
OLECHAR *moniker;
3839
CLSID clsid;
3940
CLSCTX ctx = CLSCTX_SERVER;
@@ -50,16 +51,13 @@ PHP_METHOD(com, __construct)
5051
zend_long cp = GetACP();
5152
const struct php_win32_cp *cp_it;
5253

53-
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
54-
ZEND_NUM_ARGS(), "s|S!ls",
55-
&module_name, &module_name_len, &server_name,
56-
&cp, &typelib_name, &typelib_name_len) &&
57-
FAILURE == zend_parse_parameters(
58-
ZEND_NUM_ARGS(), "sa|ls",
59-
&module_name, &module_name_len, &server_params, &cp,
60-
&typelib_name, &typelib_name_len)) {
61-
RETURN_THROWS();
62-
}
54+
ZEND_PARSE_PARAMETERS_START(1, 4)
55+
Z_PARAM_STRING(module_name, module_name_len)
56+
Z_PARAM_OPTIONAL
57+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(server_name, server_params)
58+
Z_PARAM_LONG(cp)
59+
Z_PARAM_STRING(typelib_name, typelib_name_len)
60+
ZEND_PARSE_PARAMETERS_END();
6361

6462
php_com_initialize();
6563
obj = CDNO_FETCH(object);
@@ -78,28 +76,28 @@ PHP_METHOD(com, __construct)
7876

7977
/* decode the data from the array */
8078

81-
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
79+
if (NULL != (tmp = zend_hash_str_find(server_params,
8280
"Server", sizeof("Server")-1))) {
8381
server_name = zval_get_string(tmp);
8482
ctx = CLSCTX_REMOTE_SERVER;
8583
}
8684

87-
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
85+
if (NULL != (tmp = zend_hash_str_find(server_params,
8886
"Username", sizeof("Username")-1))) {
8987
user_name = zval_get_string(tmp);
9088
}
9189

92-
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
90+
if (NULL != (tmp = zend_hash_str_find(server_params,
9391
"Password", sizeof("Password")-1))) {
9492
password = zval_get_string(tmp);
9593
}
9694

97-
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
95+
if (NULL != (tmp = zend_hash_str_find(server_params,
9896
"Domain", sizeof("Domain")-1))) {
9997
domain_name = zval_get_string(tmp);
10098
}
10199

102-
if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(server_params),
100+
if (NULL != (tmp = zend_hash_str_find(server_params,
103101
"Flags", sizeof("Flags")-1))) {
104102
ctx = (CLSCTX)zval_get_long(tmp);
105103
}
@@ -686,34 +684,35 @@ PHP_FUNCTION(com_create_guid)
686684
/* {{{ Connect events from a COM object to a PHP object */
687685
PHP_FUNCTION(com_event_sink)
688686
{
689-
zval *object, *sinkobject, *sink=NULL;
687+
zval *object, *sinkobject;
688+
zend_string *sink_str = NULL;
689+
HashTable *sink_ht = NULL;
690690
char *dispname = NULL, *typelibname = NULL;
691691
php_com_dotnet_object *obj;
692692
ITypeInfo *typeinfo = NULL;
693693

694-
RETVAL_FALSE;
694+
ZEND_PARSE_PARAMETERS_START(2, 3)
695+
Z_PARAM_OBJECT_OF_CLASS(object, php_com_variant_class_entry)
696+
Z_PARAM_OBJECT(sinkobject)
697+
Z_PARAM_OPTIONAL
698+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(sink_str, sink_ht)
699+
ZEND_PARSE_PARAMETERS_END();
695700

696-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "Oo|z/",
697-
&object, php_com_variant_class_entry, &sinkobject, &sink)) {
698-
RETURN_THROWS();
699-
}
701+
RETVAL_FALSE;
700702

701703
php_com_initialize();
702704
obj = CDNO_FETCH(object);
703705

704-
if (sink && Z_TYPE_P(sink) == IS_ARRAY) {
706+
if (sink_ht) {
705707
/* 0 => typelibname, 1 => dispname */
706708
zval *tmp;
707709

708-
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
710+
if ((tmp = zend_hash_index_find(sink_ht, 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
709711
typelibname = Z_STRVAL_P(tmp);
710-
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
712+
if ((tmp = zend_hash_index_find(sink_ht, 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
711713
dispname = Z_STRVAL_P(tmp);
712-
} else if (sink != NULL) {
713-
if (!try_convert_to_string(sink)) {
714-
RETURN_THROWS();
715-
}
716-
dispname = Z_STRVAL_P(sink);
714+
} else if (sink_str) {
715+
dispname = ZSTR_VAL(sink_str);
717716
}
718717

719718
typeinfo = php_com_locate_typeinfo(typelibname, obj, dispname, 1);

ext/com_dotnet/com_extension.stub.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ function com_get_active_object(string $progid, ?int $code_page = null): variant
5858

5959
function com_create_guid(): string|false {}
6060

61-
/** @param array|string|null $sinkinterface */
62-
function com_event_sink(variant $comobject, object $sinkobject, $sinkinterface = UNKNOWN): bool {}
61+
function com_event_sink(variant $comobject, object $sinkobject, array|string|null $sinkinterface = null): bool {}
6362

6463
/** @param com|dotnet|variant|string $comobject */
6564
function com_print_typeinfo($comobject, ?string $dispinterface = null, bool $wantsink = false): bool {}
@@ -75,8 +74,7 @@ public function __construct(mixed $value = null, int $type = VT_EMPTY, int $code
7574

7675
class com
7776
{
78-
/** @param string|array|null $server_name */
79-
public function __construct(string $module_name, $server_name = UNKNOWN, int $codepage = CP_ACP, string $typelib = "") {}
77+
public function __construct(string $module_name, array|string|null $server_name = null, int $codepage = CP_ACP, string $typelib = "") {}
8078
}
8179

8280
#if HAVE_MSCOREE_H

ext/com_dotnet/com_extension_arginfo.h

Lines changed: 3 additions & 3 deletions
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: 48167f9ee38966beaf550cd0a7b07d873575b48e */
2+
* Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
55
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
@@ -92,7 +92,7 @@ ZEND_END_ARG_INFO()
9292
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_event_sink, 0, 2, _IS_BOOL, 0)
9393
ZEND_ARG_OBJ_INFO(0, comobject, variant, 0)
9494
ZEND_ARG_TYPE_INFO(0, sinkobject, IS_OBJECT, 0)
95-
ZEND_ARG_INFO(0, sinkinterface)
95+
ZEND_ARG_TYPE_MASK(0, sinkinterface, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
9696
ZEND_END_ARG_INFO()
9797

9898
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_print_typeinfo, 0, 1, _IS_BOOL, 0)
@@ -118,7 +118,7 @@ ZEND_END_ARG_INFO()
118118

119119
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_com___construct, 0, 0, 1)
120120
ZEND_ARG_TYPE_INFO(0, module_name, IS_STRING, 0)
121-
ZEND_ARG_INFO(0, server_name)
121+
ZEND_ARG_TYPE_MASK(0, server_name, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
122122
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, codepage, IS_LONG, 0, "CP_ACP")
123123
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typelib, IS_STRING, 0, "\"\"")
124124
ZEND_END_ARG_INFO()

ext/ctype/ctype.stub.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,24 @@
22

33
/** @generate-function-entries */
44

5-
/** @param string|int $text */
65
function ctype_alnum(mixed $text): bool {}
76

8-
/** @param string|int $text */
97
function ctype_alpha(mixed $text): bool {}
108

11-
/** @param string|int $text */
129
function ctype_cntrl(mixed $text): bool {}
1310

14-
/** @param string|int $text */
1511
function ctype_digit(mixed $text): bool {}
1612

17-
/** @param string|int $text */
1813
function ctype_lower(mixed $text): bool {}
1914

20-
/** @param string|int $text */
2115
function ctype_graph(mixed $text): bool {}
2216

23-
/** @param string|int $text */
2417
function ctype_print(mixed $text): bool {}
2518

26-
/** @param string|int $text */
2719
function ctype_punct(mixed $text): bool {}
2820

29-
/** @param string|int $text */
3021
function ctype_space(mixed $text): bool {}
3122

32-
/** @param string|int $text */
3323
function ctype_upper(mixed $text): bool {}
3424

35-
/** @param string|int $text */
3625
function ctype_xdigit(mixed $text): bool {}

ext/ctype/ctype_arginfo.h

Lines changed: 1 addition & 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: 5263184b90f82d53c6da4388c79b76a8c17977e9 */
2+
* Stub hash: aa287af25fe33a05d15d85b92b0edcfae00284a2 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ctype_alnum, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, text, IS_MIXED, 0)

ext/ffi/ffi.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ static void zend_ffi_tags_cleanup(zend_ffi_dcl *dcl) /* {{{ */
35903590
ZEND_METHOD(FFI, new) /* {{{ */
35913591
{
35923592
zend_string *type_def = NULL;
3593-
zval *ztype = NULL;
3593+
zend_object *type_obj = NULL;
35943594
zend_ffi_type *type, *type_ptr;
35953595
zend_ffi_cdata *cdata;
35963596
void *ptr;
@@ -3601,11 +3601,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
36013601

36023602
ZEND_FFI_VALIDATE_API_RESTRICTION();
36033603
ZEND_PARSE_PARAMETERS_START(1, 3)
3604-
if (Z_TYPE_P(EX_VAR_NUM(0)) == IS_STRING) {
3605-
Z_PARAM_STR(type_def)
3606-
} else {
3607-
Z_PARAM_OBJECT_OF_CLASS(ztype, zend_ffi_ctype_ce)
3608-
}
3604+
Z_PARAM_STR_OR_OBJ_OF_CLASS(type_def, type_obj, zend_ffi_ctype_ce)
36093605
Z_PARAM_OPTIONAL
36103606
Z_PARAM_BOOL(owned)
36113607
Z_PARAM_BOOL(persistent)
@@ -3670,7 +3666,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
36703666

36713667
type_ptr = dcl.type;
36723668
} else {
3673-
zend_ffi_ctype *ctype = (zend_ffi_ctype*)Z_OBJ_P(ztype);
3669+
zend_ffi_ctype *ctype = (zend_ffi_ctype*) type_obj;
36743670

36753671
type_ptr = type = ctype->type;
36763672
if (ZEND_FFI_TYPE_IS_OWNED(type)) {

ext/ffi/ffi.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ public static function load(string $filename): ?FFI {}
1010

1111
public static function scope(string $scope_name): ?FFI {}
1212

13-
/** @param FFI\CType|string $type */
14-
public static function new($type, bool $owned = true, bool $persistent = false): ?FFI\CData {}
13+
public static function new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData {}
1514

1615
/** @prefer-ref $ptr */
1716
public static function free(FFI\CData $ptr): void {}

ext/ffi/ffi_arginfo.h

Lines changed: 2 additions & 2 deletions
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: a486305cd865e2798f7d9916760a3ec3c6f114b0 */
2+
* Stub hash: c5ad08a2c62988e2b50468c1c5b941b5c28f23b5 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
@@ -15,7 +15,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_scope, 0, 1, FFI, 1)
1515
ZEND_END_ARG_INFO()
1616

1717
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_new, 0, 1, FFI\\CData, 1)
18-
ZEND_ARG_INFO(0, type)
18+
ZEND_ARG_OBJ_TYPE_MASK(0, type, FFI\\CType, MAY_BE_STRING, NULL)
1919
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owned, _IS_BOOL, 0, "true")
2020
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent, _IS_BOOL, 0, "false")
2121
ZEND_END_ARG_INFO()

ext/intl/calendar/calendar.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ public function before(IntlCalendar $calendar) {}
5050
public function clear(?int $field = null) {}
5151

5252
/**
53-
* @param DateTime|string $dateTime
5453
* @return IntlCalendar|null
5554
* @alias intlcal_from_date_time
5655
*/
57-
public static function fromDateTime($dateTime, ?string $locale = null) {}
56+
public static function fromDateTime(DateTime|string $dateTime, ?string $locale = null) {}
5857

5958
/**
6059
* @return int

ext/intl/calendar/calendar_arginfo.h

Lines changed: 2 additions & 2 deletions
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: 3facb6bdce18efae3d6b9594d1fcddfb220dd54d */
2+
* Stub hash: 0ac7a1d4e011518fc956fb05624b45b061fa9710 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_clear, 0, 0, 0)
3232
ZEND_END_ARG_INFO()
3333

3434
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_fromDateTime, 0, 0, 1)
35-
ZEND_ARG_INFO(0, dateTime)
35+
ZEND_ARG_OBJ_TYPE_MASK(0, dateTime, DateTime, MAY_BE_STRING, NULL)
3636
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null")
3737
ZEND_END_ARG_INFO()
3838

0 commit comments

Comments
 (0)