Skip to content

Commit b0ca305

Browse files
committed
Add support for declaring class entries in stubs
1 parent 9719d6c commit b0ca305

35 files changed

+942
-144
lines changed

Zend/zend_exceptions.c

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -734,21 +734,10 @@ ZEND_METHOD(Exception, __toString)
734734
}
735735
/* }}} */
736736

737-
static void declare_exception_properties(zend_class_entry *ce)
737+
static void declare_extra_exception_properties(zend_class_entry *ce)
738738
{
739739
zval val;
740740

741-
zend_declare_property_string(ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
742-
zend_declare_property_string(ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);
743-
zend_declare_property_long(ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
744-
zend_declare_property_null(ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED);
745-
zend_declare_property_null(ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
746-
747-
ZVAL_EMPTY_ARRAY(&val);
748-
zend_declare_typed_property(
749-
ce, ZSTR_KNOWN(ZEND_STR_TRACE), &val, ZEND_ACC_PRIVATE, NULL,
750-
(zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
751-
752741
ZVAL_NULL(&val);
753742
zend_declare_typed_property(
754743
ce, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &val, ZEND_ACC_PRIVATE, NULL,
@@ -757,64 +746,49 @@ static void declare_exception_properties(zend_class_entry *ce)
757746

758747
void zend_register_default_exception(void) /* {{{ */
759748
{
760-
zend_class_entry ce;
761-
762-
REGISTER_MAGIC_INTERFACE(throwable, Throwable);
763-
zend_class_implements(zend_ce_throwable, 1, zend_ce_stringable);
749+
zend_ce_throwable = register_class_Throwable(zend_ce_stringable);
750+
zend_ce_throwable->interface_gets_implemented = zend_implement_throwable;
764751

765752
memcpy(&default_exception_handlers, &std_object_handlers, sizeof(zend_object_handlers));
766753
default_exception_handlers.clone_obj = NULL;
767754

768-
INIT_CLASS_ENTRY(ce, "Exception", class_Exception_methods);
769-
zend_ce_exception = zend_register_internal_class_ex(&ce, NULL);
755+
zend_ce_exception = register_class_Exception(zend_ce_throwable);
770756
zend_ce_exception->create_object = zend_default_exception_new;
771-
zend_class_implements(zend_ce_exception, 1, zend_ce_throwable);
772-
declare_exception_properties(zend_ce_exception);
757+
declare_extra_exception_properties(zend_ce_error);
773758

774-
INIT_CLASS_ENTRY(ce, "ErrorException", class_ErrorException_methods);
775-
zend_ce_error_exception = zend_register_internal_class_ex(&ce, zend_ce_exception);
759+
zend_ce_error_exception = register_class_ErrorException(zend_ce_exception);
776760
zend_ce_error_exception->create_object = zend_error_exception_new;
777761
zend_declare_property_long(zend_ce_error_exception, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
778762

779-
INIT_CLASS_ENTRY(ce, "Error", class_Error_methods);
780-
zend_ce_error = zend_register_internal_class_ex(&ce, NULL);
763+
zend_ce_error = register_class_Error(zend_ce_throwable);
781764
zend_ce_error->create_object = zend_default_exception_new;
782-
zend_class_implements(zend_ce_error, 1, zend_ce_throwable);
783-
declare_exception_properties(zend_ce_error);
765+
declare_extra_exception_properties(zend_ce_error);
784766

785-
INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
786-
zend_ce_compile_error = zend_register_internal_class_ex(&ce, zend_ce_error);
767+
zend_ce_compile_error = register_class_CompileError(zend_ce_error);
787768
zend_ce_compile_error->create_object = zend_default_exception_new;
788769

789-
INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
790-
zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_compile_error);
770+
zend_ce_parse_error = register_class_ParseError(zend_ce_compile_error);
791771
zend_ce_parse_error->create_object = zend_default_exception_new;
792772

793-
INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
794-
zend_ce_type_error = zend_register_internal_class_ex(&ce, zend_ce_error);
773+
zend_ce_type_error = register_class_TypeError(zend_ce_error);
795774
zend_ce_type_error->create_object = zend_default_exception_new;
796775

797-
INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
798-
zend_ce_argument_count_error = zend_register_internal_class_ex(&ce, zend_ce_type_error);
776+
zend_ce_argument_count_error = register_class_ArgumentCountError(zend_ce_type_error);
799777
zend_ce_argument_count_error->create_object = zend_default_exception_new;
800778

801-
INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
802-
zend_ce_value_error = zend_register_internal_class_ex(&ce, zend_ce_error);
779+
zend_ce_value_error = register_class_ValueError(zend_ce_error);
803780
zend_ce_value_error->create_object = zend_default_exception_new;
804781

805-
INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
806-
zend_ce_arithmetic_error = zend_register_internal_class_ex(&ce, zend_ce_error);
782+
zend_ce_arithmetic_error = register_class_ArithmeticError(zend_ce_error);
807783
zend_ce_arithmetic_error->create_object = zend_default_exception_new;
808784

809-
INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
810-
zend_ce_division_by_zero_error = zend_register_internal_class_ex(&ce, zend_ce_arithmetic_error);
785+
zend_ce_division_by_zero_error = register_class_DivisionByZeroError(zend_ce_arithmetic_error);
811786
zend_ce_division_by_zero_error->create_object = zend_default_exception_new;
812787

813-
INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
814-
815-
INIT_CLASS_ENTRY(ce, "UnhandledMatchError", NULL);
816-
zend_ce_unhandled_match_error = zend_register_internal_class_ex(&ce, zend_ce_error);
788+
zend_ce_unhandled_match_error = register_class_UnhandledMatchError(zend_ce_error);
817789
zend_ce_unhandled_match_error->create_object = zend_default_exception_new;
790+
791+
INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
818792
}
819793
/* }}} */
820794

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() {}
2644

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

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

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

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

@@ -119,3 +162,7 @@ class ArithmeticError extends Error
119162
class DivisionByZeroError extends ArithmeticError
120163
{
121164
}
165+
166+
class UnhandledMatchError extends Error
167+
{
168+
}

Zend/zend_exceptions_arginfo.h

Lines changed: 145 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: bc49b326136997660887b12f0c59f8a57b17ecaf */
2+
* Stub hash: 8593bcd9dd8350f84533b9592c3d6a2885e97d07 */
33

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

0 commit comments

Comments
 (0)