Skip to content

Commit 3e07456

Browse files
kocsismatenikic
authored andcommitted
Add support for declaring class entries in stubs
1 parent 9be0ee4 commit 3e07456

Some content is hidden

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

47 files changed

+1264
-248
lines changed

Zend/zend_exceptions.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ void zend_register_default_exception(void) /* {{{ */
765765
{
766766
zend_class_entry ce;
767767

768-
REGISTER_MAGIC_INTERFACE(throwable, Throwable);
769-
zend_class_implements(zend_ce_throwable, 1, zend_ce_stringable);
768+
zend_ce_throwable = register_class_Throwable(zend_ce_stringable);
769+
zend_ce_throwable->interface_gets_implemented = zend_implement_throwable;
770770

771771
memcpy(&default_exception_handlers, &std_object_handlers, sizeof(zend_object_handlers));
772772
default_exception_handlers.clone_obj = NULL;
@@ -777,8 +777,7 @@ void zend_register_default_exception(void) /* {{{ */
777777
zend_class_implements(zend_ce_exception, 1, zend_ce_throwable);
778778
declare_exception_properties(zend_ce_exception);
779779

780-
INIT_CLASS_ENTRY(ce, "ErrorException", class_ErrorException_methods);
781-
zend_ce_error_exception = zend_register_internal_class_ex(&ce, zend_ce_exception);
780+
zend_ce_error_exception = register_class_ErrorException(zend_ce_exception);
782781
zend_ce_error_exception->create_object = zend_error_exception_new;
783782
zend_declare_property_long(zend_ce_error_exception, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
784783

@@ -788,39 +787,31 @@ void zend_register_default_exception(void) /* {{{ */
788787
zend_class_implements(zend_ce_error, 1, zend_ce_throwable);
789788
declare_exception_properties(zend_ce_error);
790789

791-
INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
792-
zend_ce_compile_error = zend_register_internal_class_ex(&ce, zend_ce_error);
790+
zend_ce_compile_error = register_class_CompileError(zend_ce_error);
793791
zend_ce_compile_error->create_object = zend_default_exception_new;
794792

795-
INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
796-
zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_compile_error);
793+
zend_ce_parse_error = register_class_ParseError(zend_ce_compile_error);
797794
zend_ce_parse_error->create_object = zend_default_exception_new;
798795

799-
INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
800-
zend_ce_type_error = zend_register_internal_class_ex(&ce, zend_ce_error);
796+
zend_ce_type_error = register_class_TypeError(zend_ce_error);
801797
zend_ce_type_error->create_object = zend_default_exception_new;
802798

803-
INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
804-
zend_ce_argument_count_error = zend_register_internal_class_ex(&ce, zend_ce_type_error);
799+
zend_ce_argument_count_error = register_class_ArgumentCountError(zend_ce_type_error);
805800
zend_ce_argument_count_error->create_object = zend_default_exception_new;
806801

807-
INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
808-
zend_ce_value_error = zend_register_internal_class_ex(&ce, zend_ce_error);
802+
zend_ce_value_error = register_class_ValueError(zend_ce_error);
809803
zend_ce_value_error->create_object = zend_default_exception_new;
810804

811-
INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
812-
zend_ce_arithmetic_error = zend_register_internal_class_ex(&ce, zend_ce_error);
805+
zend_ce_arithmetic_error = register_class_ArithmeticError(zend_ce_error);
813806
zend_ce_arithmetic_error->create_object = zend_default_exception_new;
814807

815-
INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
816-
zend_ce_division_by_zero_error = zend_register_internal_class_ex(&ce, zend_ce_arithmetic_error);
808+
zend_ce_division_by_zero_error = register_class_DivisionByZeroError(zend_ce_arithmetic_error);
817809
zend_ce_division_by_zero_error->create_object = zend_default_exception_new;
818810

819-
INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
820-
821-
INIT_CLASS_ENTRY(ce, "UnhandledMatchError", NULL);
822-
zend_ce_unhandled_match_error = zend_register_internal_class_ex(&ce, zend_ce_error);
811+
zend_ce_unhandled_match_error = register_class_UnhandledMatchError(zend_ce_error);
823812
zend_ce_unhandled_match_error->create_object = zend_default_exception_new;
813+
814+
INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
824815
}
825816
/* }}} */
826817

Zend/zend_exceptions.stub.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
/** @generate-function-entries */
3+
/**
4+
* @generate-function-entries
5+
* @generate-class-entries
6+
*/
47

58
interface Throwable extends Stringable
69
{
@@ -22,6 +25,21 @@ public function getTraceAsString(): string;
2225

2326
class Exception implements Throwable
2427
{
28+
/** @var string */
29+
protected $message = "";
30+
/** @var string */
31+
private $string = "";
32+
/** @var int */
33+
protected $code = 0;
34+
/** @var string|null */
35+
protected $file = null;
36+
/** @var int|null */
37+
protected $line = null;
38+
/** @known */
39+
private array $trace = [];
40+
/** @known */
41+
private ?Throwable $previous = null;
42+
2543
final private function __clone(): void {}
2644

2745
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null) {}
@@ -49,13 +67,38 @@ public function __toString(): string {}
4967

5068
class ErrorException extends Exception
5169
{
52-
public function __construct(string $message = "", int $code = 0, int $severity = E_ERROR, ?string $filename = null, ?int $line = null, ?Throwable $previous = null) {}
70+
/** @var int */
71+
protected $severity = E_ERROR;
72+
73+
public function __construct(
74+
string $message = "",
75+
int $code = 0,
76+
int $severity = E_ERROR,
77+
?string $filename = null,
78+
?int $line = null,
79+
?Throwable $previous = null
80+
) {}
5381

5482
final public function getSeverity(): int {}
5583
}
5684

5785
class Error implements Throwable
5886
{
87+
/** @var string */
88+
protected $message = "";
89+
/** @var string */
90+
private $string = "";
91+
/** @var int */
92+
protected $code = 0;
93+
/** @var string|null */
94+
protected $file = null;
95+
/** @var int|null */
96+
protected $line = null;
97+
/** @known */
98+
private array $trace = [];
99+
/** @known */
100+
private ?Throwable $previous = null;
101+
59102
/** @implementation-alias Exception::__clone */
60103
final private function __clone(): void {}
61104

@@ -123,3 +166,7 @@ class ArithmeticError extends Error
123166
class DivisionByZeroError extends ArithmeticError
124167
{
125168
}
169+
170+
class UnhandledMatchError extends Error
171+
{
172+
}

Zend/zend_exceptions_arginfo.h

Lines changed: 166 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: 3699b51b31e509c11435845c7e0d35a2608dd268 */
2+
* Stub hash: fc90f59a8c670e7874f4a7564333c5b22c0eea5e */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -180,3 +180,168 @@ static const zend_function_entry class_ArithmeticError_methods[] = {
180180
static const zend_function_entry class_DivisionByZeroError_methods[] = {
181181
ZEND_FE_END
182182
};
183+
184+
185+
static const zend_function_entry class_UnhandledMatchError_methods[] = {
186+
ZEND_FE_END
187+
};
188+
189+
zend_class_entry *register_class_Throwable(zend_class_entry *class_entry_Stringable)
190+
{
191+
zend_class_entry ce, *class_entry;
192+
193+
INIT_CLASS_ENTRY(ce, "Throwable", class_Throwable_methods);
194+
class_entry = zend_register_internal_interface(&ce);
195+
zend_class_implements(class_entry, 1, class_entry_Stringable);
196+
197+
return class_entry;
198+
}
199+
200+
zend_class_entry *register_class_Exception(zend_class_entry *class_entry_Throwable)
201+
{
202+
zend_class_entry ce, *class_entry;
203+
204+
INIT_CLASS_ENTRY(ce, "Exception", class_Exception_methods);
205+
class_entry = zend_register_internal_class_ex(&ce, NULL);
206+
zend_class_implements(class_entry, 1, class_entry_Throwable);
207+
208+
zend_declare_property_string(class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PROTECTED);
209+
210+
zend_declare_property_string(class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE);
211+
212+
zend_declare_property_long(class_entry, "code", sizeof("code") - 1, 0, ZEND_ACC_PROTECTED);
213+
214+
zend_declare_property_null(class_entry, "file", sizeof("file") - 1, ZEND_ACC_PROTECTED);
215+
216+
zend_declare_property_null(class_entry, "line", sizeof("line") - 1, ZEND_ACC_PROTECTED);
217+
218+
zval property_trace_default_value;
219+
ZVAL_EMPTY_ARRAY(&property_trace_default_value);
220+
zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_TRACE), &property_trace_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
221+
222+
zval property_previous_default_value;
223+
ZVAL_NULL(&property_previous_default_value);
224+
zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &property_previous_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_CE(class_entry_Throwable, 1, 0));
225+
226+
return class_entry;
227+
}
228+
229+
zend_class_entry *register_class_ErrorException(zend_class_entry *class_entry_Exception)
230+
{
231+
zend_class_entry ce, *class_entry;
232+
233+
INIT_CLASS_ENTRY(ce, "ErrorException", class_ErrorException_methods);
234+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Exception);
235+
236+
return class_entry;
237+
}
238+
239+
zend_class_entry *register_class_Error(zend_class_entry *class_entry_Throwable)
240+
{
241+
zend_class_entry ce, *class_entry;
242+
243+
INIT_CLASS_ENTRY(ce, "Error", class_Error_methods);
244+
class_entry = zend_register_internal_class_ex(&ce, NULL);
245+
zend_class_implements(class_entry, 1, class_entry_Throwable);
246+
247+
zend_declare_property_string(class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PROTECTED);
248+
249+
zend_declare_property_string(class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE);
250+
251+
zend_declare_property_long(class_entry, "code", sizeof("code") - 1, 0, ZEND_ACC_PROTECTED);
252+
253+
zend_declare_property_null(class_entry, "file", sizeof("file") - 1, ZEND_ACC_PROTECTED);
254+
255+
zend_declare_property_null(class_entry, "line", sizeof("line") - 1, ZEND_ACC_PROTECTED);
256+
257+
zval property_trace_default_value;
258+
ZVAL_EMPTY_ARRAY(&property_trace_default_value);
259+
zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_TRACE), &property_trace_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
260+
261+
zval property_previous_default_value;
262+
ZVAL_NULL(&property_previous_default_value);
263+
zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &property_previous_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_CE(class_entry_Throwable, 1, 0));
264+
265+
return class_entry;
266+
}
267+
268+
zend_class_entry *register_class_CompileError(zend_class_entry *class_entry_Error)
269+
{
270+
zend_class_entry ce, *class_entry;
271+
272+
INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
273+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);
274+
275+
return class_entry;
276+
}
277+
278+
zend_class_entry *register_class_ParseError(zend_class_entry *class_entry_CompileError)
279+
{
280+
zend_class_entry ce, *class_entry;
281+
282+
INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
283+
class_entry = zend_register_internal_class_ex(&ce, class_entry_CompileError);
284+
285+
return class_entry;
286+
}
287+
288+
zend_class_entry *register_class_TypeError(zend_class_entry *class_entry_Error)
289+
{
290+
zend_class_entry ce, *class_entry;
291+
292+
INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
293+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);
294+
295+
return class_entry;
296+
}
297+
298+
zend_class_entry *register_class_ArgumentCountError(zend_class_entry *class_entry_TypeError)
299+
{
300+
zend_class_entry ce, *class_entry;
301+
302+
INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
303+
class_entry = zend_register_internal_class_ex(&ce, class_entry_TypeError);
304+
305+
return class_entry;
306+
}
307+
308+
zend_class_entry *register_class_ValueError(zend_class_entry *class_entry_Error)
309+
{
310+
zend_class_entry ce, *class_entry;
311+
312+
INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
313+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);
314+
315+
return class_entry;
316+
}
317+
318+
zend_class_entry *register_class_ArithmeticError(zend_class_entry *class_entry_Error)
319+
{
320+
zend_class_entry ce, *class_entry;
321+
322+
INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
323+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);
324+
325+
return class_entry;
326+
}
327+
328+
zend_class_entry *register_class_DivisionByZeroError(zend_class_entry *class_entry_ArithmeticError)
329+
{
330+
zend_class_entry ce, *class_entry;
331+
332+
INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
333+
class_entry = zend_register_internal_class_ex(&ce, class_entry_ArithmeticError);
334+
335+
return class_entry;
336+
}
337+
338+
zend_class_entry *register_class_UnhandledMatchError(zend_class_entry *class_entry_Error)
339+
{
340+
zend_class_entry ce, *class_entry;
341+
342+
INIT_CLASS_ENTRY(ce, "UnhandledMatchError", class_UnhandledMatchError_methods);
343+
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);
344+
345+
return class_entry;
346+
}
347+

Zend/zend_generators.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,17 +1112,11 @@ zend_object_iterator *zend_generator_get_iterator(zend_class_entry *ce, zval *ob
11121112

11131113
void zend_register_generator_ce(void) /* {{{ */
11141114
{
1115-
zend_class_entry ce;
1116-
1117-
INIT_CLASS_ENTRY(ce, "Generator", class_Generator_methods);
1118-
zend_ce_generator = zend_register_internal_class(&ce);
1119-
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
1115+
zend_ce_generator = register_class_Generator(zend_ce_iterator);
11201116
zend_ce_generator->create_object = zend_generator_create;
11211117
zend_ce_generator->serialize = zend_class_serialize_deny;
11221118
zend_ce_generator->unserialize = zend_class_unserialize_deny;
1123-
11241119
/* get_iterator has to be assigned *after* implementing the interface */
1125-
zend_class_implements(zend_ce_generator, 1, zend_ce_iterator);
11261120
zend_ce_generator->get_iterator = zend_generator_get_iterator;
11271121

11281122
memcpy(&zend_generator_handlers, &std_object_handlers, sizeof(zend_object_handlers));
@@ -1132,7 +1126,6 @@ void zend_register_generator_ce(void) /* {{{ */
11321126
zend_generator_handlers.clone_obj = NULL;
11331127
zend_generator_handlers.get_constructor = zend_generator_get_constructor;
11341128

1135-
INIT_CLASS_ENTRY(ce, "ClosedGeneratorException", NULL);
1136-
zend_ce_ClosedGeneratorException = zend_register_internal_class_ex(&ce, zend_ce_exception);
1129+
zend_ce_ClosedGeneratorException = register_class_ClosedGeneratorException(zend_ce_exception);
11371130
}
11381131
/* }}} */

Zend/zend_generators.stub.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

3-
/** @generate-function-entries */
3+
/**
4+
* @generate-function-entries
5+
* @generate-class-entries
6+
*/
47

8+
/** @strict-properties */
59
final class Generator implements Iterator
610
{
711
public function rewind(): void {}
@@ -20,3 +24,7 @@ public function throw(Throwable $exception): mixed {}
2024

2125
public function getReturn(): mixed {}
2226
}
27+
28+
class ClosedGeneratorException extends Exception
29+
{
30+
}

0 commit comments

Comments
 (0)