Skip to content

Commit 6e58831

Browse files
committed
Generate method entries from stubs for Zend classes
1 parent 77ee4e6 commit 6e58831

14 files changed

+368
-181
lines changed

Zend/zend_exceptions.c

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static zend_object *zend_error_exception_new(zend_class_entry *class_type) /* {{
258258

259259
/* {{{ proto Exception|Error Exception|Error::__clone()
260260
Clone the exception object */
261-
ZEND_COLD ZEND_METHOD(exception, __clone)
261+
ZEND_COLD ZEND_METHOD(Exception, __clone)
262262
{
263263
/* Should never be executable */
264264
zend_throw_exception(NULL, "Cannot clone object using __clone()", 0);
@@ -267,7 +267,7 @@ ZEND_COLD ZEND_METHOD(exception, __clone)
267267

268268
/* {{{ proto Exception|Error::__construct(string message, int code [, Throwable previous])
269269
Exception constructor */
270-
ZEND_METHOD(exception, __construct)
270+
ZEND_METHOD(Exception, __construct)
271271
{
272272
zend_string *message = NULL;
273273
zend_long code = 0;
@@ -316,7 +316,7 @@ ZEND_METHOD(exception, __construct)
316316
zend_unset_property(i_get_exception_base(object), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \
317317
}
318318

319-
ZEND_METHOD(exception, __wakeup)
319+
ZEND_METHOD(Exception, __wakeup)
320320
{
321321
zval value, *pvalue;
322322
zval *object = ZEND_THIS;
@@ -337,7 +337,7 @@ ZEND_METHOD(exception, __wakeup)
337337

338338
/* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Throwable previous]]])
339339
ErrorException constructor */
340-
ZEND_METHOD(error_exception, __construct)
340+
ZEND_METHOD(ErrorException, __construct)
341341
{
342342
zend_string *message = NULL, *filename = NULL;
343343
zend_long code = 0, severity = E_ERROR, lineno;
@@ -398,7 +398,7 @@ ZEND_METHOD(error_exception, __construct)
398398

399399
/* {{{ proto string Exception|Error::getFile()
400400
Get the file in which the exception occurred */
401-
ZEND_METHOD(exception, getFile)
401+
ZEND_METHOD(Exception, getFile)
402402
{
403403
zval *prop, rv;
404404

@@ -412,7 +412,7 @@ ZEND_METHOD(exception, getFile)
412412

413413
/* {{{ proto int Exception|Error::getLine()
414414
Get the line in which the exception occurred */
415-
ZEND_METHOD(exception, getLine)
415+
ZEND_METHOD(Exception, getLine)
416416
{
417417
zval *prop, rv;
418418

@@ -426,7 +426,7 @@ ZEND_METHOD(exception, getLine)
426426

427427
/* {{{ proto string Exception|Error::getMessage()
428428
Get the exception message */
429-
ZEND_METHOD(exception, getMessage)
429+
ZEND_METHOD(Exception, getMessage)
430430
{
431431
zval *prop, rv;
432432

@@ -440,7 +440,7 @@ ZEND_METHOD(exception, getMessage)
440440

441441
/* {{{ proto int Exception|Error::getCode()
442442
Get the exception code */
443-
ZEND_METHOD(exception, getCode)
443+
ZEND_METHOD(Exception, getCode)
444444
{
445445
zval *prop, rv;
446446

@@ -454,7 +454,7 @@ ZEND_METHOD(exception, getCode)
454454

455455
/* {{{ proto array Exception|Error::getTrace()
456456
Get the stack trace for the location in which the exception occurred */
457-
ZEND_METHOD(exception, getTrace)
457+
ZEND_METHOD(Exception, getTrace)
458458
{
459459
zval *prop, rv;
460460

@@ -468,7 +468,7 @@ ZEND_METHOD(exception, getTrace)
468468

469469
/* {{{ proto int ErrorException::getSeverity()
470470
Get the exception severity */
471-
ZEND_METHOD(error_exception, getSeverity)
471+
ZEND_METHOD(ErrorException, getSeverity)
472472
{
473473
zval *prop, rv;
474474

@@ -611,7 +611,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /*
611611

612612
/* {{{ proto string Exception|Error::getTraceAsString()
613613
Obtain the backtrace for the exception as a string (instead of an array) */
614-
ZEND_METHOD(exception, getTraceAsString)
614+
ZEND_METHOD(Exception, getTraceAsString)
615615
{
616616
zval *trace, *frame, rv;
617617
zend_ulong index;
@@ -650,7 +650,7 @@ ZEND_METHOD(exception, getTraceAsString)
650650

651651
/* {{{ proto Throwable Exception|Error::getPrevious()
652652
Return previous Throwable or NULL. */
653-
ZEND_METHOD(exception, getPrevious)
653+
ZEND_METHOD(Exception, getPrevious)
654654
{
655655
zval rv;
656656

@@ -661,7 +661,7 @@ ZEND_METHOD(exception, getPrevious)
661661

662662
/* {{{ proto string Exception|Error::__toString()
663663
Obtain the string representation of the Exception object */
664-
ZEND_METHOD(exception, __toString)
664+
ZEND_METHOD(Exception, __toString)
665665
{
666666
zval trace, *exception;
667667
zend_class_entry *base_ce;
@@ -754,51 +754,6 @@ ZEND_METHOD(exception, __toString)
754754
}
755755
/* }}} */
756756

757-
/** {{{ Throwable method definition */
758-
static const zend_function_entry zend_funcs_throwable[] = {
759-
ZEND_ABSTRACT_ME(throwable, getMessage, arginfo_class_Throwable_getMessage)
760-
ZEND_ABSTRACT_ME(throwable, getCode, arginfo_class_Throwable_getCode)
761-
ZEND_ABSTRACT_ME(throwable, getFile, arginfo_class_Throwable_getFile)
762-
ZEND_ABSTRACT_ME(throwable, getLine, arginfo_class_Throwable_getLine)
763-
ZEND_ABSTRACT_ME(throwable, getTrace, arginfo_class_Throwable_getTrace)
764-
ZEND_ABSTRACT_ME(throwable, getPrevious, arginfo_class_Throwable_getPrevious)
765-
ZEND_ABSTRACT_ME(throwable, getTraceAsString, arginfo_class_Throwable_getTraceAsString)
766-
ZEND_FE_END
767-
};
768-
/* }}} */
769-
770-
/* {{{ internal structs */
771-
/* All functions that may be used in uncaught exception handlers must be final
772-
* and must not throw exceptions. Otherwise we would need a facility to handle
773-
* such exceptions in that handler.
774-
* Also all getXY() methods are final because thy serve as read only access to
775-
* their corresponding properties, no more, no less. If after all you need to
776-
* override something then it is method __toString().
777-
* And never try to change the state of exceptions and never implement anything
778-
* that gives the user anything to accomplish this.
779-
*/
780-
static const zend_function_entry default_exception_functions[] = {
781-
ZEND_ME(exception, __clone, arginfo_class_Exception___clone, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
782-
ZEND_ME(exception, __construct, arginfo_class_Exception___construct, ZEND_ACC_PUBLIC)
783-
ZEND_ME(exception, __wakeup, arginfo_class_Exception___wakeup, ZEND_ACC_PUBLIC)
784-
ZEND_ME(exception, getMessage, arginfo_class_Exception_getMessage, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
785-
ZEND_ME(exception, getCode, arginfo_class_Exception_getCode, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
786-
ZEND_ME(exception, getFile, arginfo_class_Exception_getFile, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
787-
ZEND_ME(exception, getLine, arginfo_class_Exception_getLine, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
788-
ZEND_ME(exception, getTrace, arginfo_class_Exception_getTrace, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
789-
ZEND_ME(exception, getPrevious, arginfo_class_Exception_getPrevious, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
790-
ZEND_ME(exception, getTraceAsString, arginfo_class_Exception_getTraceAsString, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
791-
ZEND_ME(exception, __toString, arginfo_class_Exception___toString, 0)
792-
ZEND_FE_END
793-
};
794-
795-
static const zend_function_entry error_exception_functions[] = {
796-
ZEND_ME(error_exception, __construct, arginfo_class_ErrorException___construct, ZEND_ACC_PUBLIC)
797-
ZEND_ME(error_exception, getSeverity, arginfo_class_ErrorException_getSeverity, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
798-
ZEND_FE_END
799-
};
800-
/* }}} */
801-
802757
void zend_register_default_exception(void) /* {{{ */
803758
{
804759
zend_class_entry ce;
@@ -809,7 +764,7 @@ void zend_register_default_exception(void) /* {{{ */
809764
memcpy(&default_exception_handlers, &std_object_handlers, sizeof(zend_object_handlers));
810765
default_exception_handlers.clone_obj = NULL;
811766

812-
INIT_CLASS_ENTRY(ce, "Exception", default_exception_functions);
767+
INIT_CLASS_ENTRY(ce, "Exception", class_Exception_methods);
813768
zend_ce_exception = zend_register_internal_class_ex(&ce, NULL);
814769
zend_ce_exception->create_object = zend_default_exception_new;
815770
zend_class_implements(zend_ce_exception, 1, zend_ce_throwable);
@@ -822,12 +777,12 @@ void zend_register_default_exception(void) /* {{{ */
822777
zend_declare_property_null(zend_ce_exception, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
823778
zend_declare_property_null(zend_ce_exception, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);
824779

825-
INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions);
780+
INIT_CLASS_ENTRY(ce, "ErrorException", class_ErrorException_methods);
826781
zend_ce_error_exception = zend_register_internal_class_ex(&ce, zend_ce_exception);
827782
zend_ce_error_exception->create_object = zend_error_exception_new;
828783
zend_declare_property_long(zend_ce_error_exception, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
829784

830-
INIT_CLASS_ENTRY(ce, "Error", default_exception_functions);
785+
INIT_CLASS_ENTRY(ce, "Error", class_Error_methods);
831786
zend_ce_error = zend_register_internal_class_ex(&ce, NULL);
832787
zend_ce_error->create_object = zend_default_exception_new;
833788
zend_class_implements(zend_ce_error, 1, zend_ce_throwable);
@@ -840,31 +795,31 @@ void zend_register_default_exception(void) /* {{{ */
840795
zend_declare_property_null(zend_ce_error, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
841796
zend_declare_property_null(zend_ce_error, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);
842797

843-
INIT_CLASS_ENTRY(ce, "CompileError", NULL);
798+
INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
844799
zend_ce_compile_error = zend_register_internal_class_ex(&ce, zend_ce_error);
845800
zend_ce_compile_error->create_object = zend_default_exception_new;
846801

847-
INIT_CLASS_ENTRY(ce, "ParseError", NULL);
802+
INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
848803
zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_compile_error);
849804
zend_ce_parse_error->create_object = zend_default_exception_new;
850805

851-
INIT_CLASS_ENTRY(ce, "TypeError", NULL);
806+
INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
852807
zend_ce_type_error = zend_register_internal_class_ex(&ce, zend_ce_error);
853808
zend_ce_type_error->create_object = zend_default_exception_new;
854809

855-
INIT_CLASS_ENTRY(ce, "ArgumentCountError", NULL);
810+
INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
856811
zend_ce_argument_count_error = zend_register_internal_class_ex(&ce, zend_ce_type_error);
857812
zend_ce_argument_count_error->create_object = zend_default_exception_new;
858813

859-
INIT_CLASS_ENTRY(ce, "ValueError", NULL);
814+
INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
860815
zend_ce_value_error = zend_register_internal_class_ex(&ce, zend_ce_error);
861816
zend_ce_value_error->create_object = zend_default_exception_new;
862817

863-
INIT_CLASS_ENTRY(ce, "ArithmeticError", NULL);
818+
INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
864819
zend_ce_arithmetic_error = zend_register_internal_class_ex(&ce, zend_ce_error);
865820
zend_ce_arithmetic_error->create_object = zend_default_exception_new;
866821

867-
INIT_CLASS_ENTRY(ce, "DivisionByZeroError", NULL);
822+
INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
868823
zend_ce_division_by_zero_error = zend_register_internal_class_ex(&ce, zend_ce_arithmetic_error);
869824
zend_ce_division_by_zero_error->create_object = zend_default_exception_new;
870825
}

Zend/zend_exceptions.stub.php

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @generate-function-entries */
4+
35
interface Throwable extends Stringable
46
{
57
/** @return string */
@@ -32,26 +34,20 @@ public function __construct(string $message = UNKNOWN, int $code = 0, ?Throwable
3234

3335
public function __wakeup() {}
3436

35-
/** @return string */
36-
final public function getMessage() {}
37+
final public function getMessage(): string {}
3738

3839
/** @return int */
3940
final public function getCode() {}
4041

41-
/** @return string */
42-
final public function getFile() {}
42+
final public function getFile(): string {}
4343

44-
/** @return int */
45-
final public function getLine() {}
44+
final public function getLine(): int {}
4645

47-
/** @return array */
48-
final public function getTrace() {}
46+
final public function getTrace(): array {}
4947

50-
/** @return ?Throwable */
51-
final public function getPrevious() {}
48+
final public function getPrevious(): ?Throwable {}
5249

53-
/** @return string */
54-
final public function getTraceAsString() {}
50+
final public function getTraceAsString(): string {}
5551

5652
public function __toString(): string {}
5753
}
@@ -60,6 +56,72 @@ class ErrorException extends Exception
6056
{
6157
public function __construct(string $message = UNKNOWN, int $code = 0, int $severity = E_ERROR, string $filename = UNKNOWN, int $lineno = 0, ?Throwable $previous = null) {}
6258

63-
/** @return int */
64-
final public function getSeverity() {}
59+
final public function getSeverity(): int {}
60+
}
61+
62+
class Error implements Throwable
63+
{
64+
/** @alias Exception::__clone */
65+
final private function __clone() {}
66+
67+
/** @alias Exception::__construct */
68+
public function __construct(string $message = UNKNOWN, int $code = 0, ?Throwable $previous = null) {}
69+
70+
/** @alias Exception::__wakeup */
71+
public function __wakeup() {}
72+
73+
/** @alias Exception::getMessage */
74+
final public function getMessage(): string {}
75+
76+
/**
77+
* @return int
78+
* @alias Exception::getCode
79+
*/
80+
final public function getCode() {}
81+
82+
/** @alias Exception::getFile */
83+
final public function getFile(): string {}
84+
85+
/** @alias Exception::getLine */
86+
final public function getLine(): int {}
87+
88+
/** @alias Exception::getTrace */
89+
final public function getTrace(): array {}
90+
91+
/** @alias Exception::getPrevious */
92+
final public function getPrevious(): ?Throwable {}
93+
94+
/** @alias Exception::getTraceAsString */
95+
final public function getTraceAsString(): string {}
96+
97+
/** @alias Exception::__toString */
98+
public function __toString(): string {}
99+
}
100+
101+
class CompileError extends Error
102+
{
103+
}
104+
105+
class ParseError extends CompileError
106+
{
107+
}
108+
109+
class TypeError extends Error
110+
{
111+
}
112+
113+
class ArgumentCountError extends TypeError
114+
{
115+
}
116+
117+
class ValueError extends Error
118+
{
119+
}
120+
121+
class ArithmeticError extends Error
122+
{
123+
}
124+
125+
class DivisionByZeroError extends ArithmeticError
126+
{
65127
}

0 commit comments

Comments
 (0)