Skip to content

Add support for generating class entries from stubs #6289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ void zend_register_default_exception(void) /* {{{ */
{
zend_class_entry ce;

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

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

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

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

INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
zend_ce_compile_error = zend_register_internal_class_ex(&ce, zend_ce_error);
zend_ce_compile_error = register_class_CompileError(zend_ce_error);
zend_ce_compile_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_compile_error);
zend_ce_parse_error = register_class_ParseError(zend_ce_compile_error);
zend_ce_parse_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
zend_ce_type_error = zend_register_internal_class_ex(&ce, zend_ce_error);
zend_ce_type_error = register_class_TypeError(zend_ce_error);
zend_ce_type_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
zend_ce_argument_count_error = zend_register_internal_class_ex(&ce, zend_ce_type_error);
zend_ce_argument_count_error = register_class_ArgumentCountError(zend_ce_type_error);
zend_ce_argument_count_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
zend_ce_value_error = zend_register_internal_class_ex(&ce, zend_ce_error);
zend_ce_value_error = register_class_ValueError(zend_ce_error);
zend_ce_value_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
zend_ce_arithmetic_error = zend_register_internal_class_ex(&ce, zend_ce_error);
zend_ce_arithmetic_error = register_class_ArithmeticError(zend_ce_error);
zend_ce_arithmetic_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
zend_ce_division_by_zero_error = zend_register_internal_class_ex(&ce, zend_ce_arithmetic_error);
zend_ce_division_by_zero_error = register_class_DivisionByZeroError(zend_ce_arithmetic_error);
zend_ce_division_by_zero_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);

INIT_CLASS_ENTRY(ce, "UnhandledMatchError", NULL);
zend_ce_unhandled_match_error = zend_register_internal_class_ex(&ce, zend_ce_error);
zend_ce_unhandled_match_error = register_class_UnhandledMatchError(zend_ce_error);
zend_ce_unhandled_match_error->create_object = zend_default_exception_new;

INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
}
/* }}} */

Expand Down
51 changes: 49 additions & 2 deletions Zend/zend_exceptions.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

/** @generate-function-entries */
/**
* @generate-function-entries
* @generate-class-entries
*/

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

class Exception implements Throwable
{
/** @var string */
protected $message = "";
/** @var string */
private $string = "";
/** @var int */
protected $code = 0;
/** @var string|null */
protected $file = null;
/** @var int|null */
protected $line = null;
/** @known */
private array $trace = [];
/** @known */
private ?Throwable $previous = null;

final private function __clone(): void {}

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

class ErrorException extends Exception
{
public function __construct(string $message = "", int $code = 0, int $severity = E_ERROR, ?string $filename = null, ?int $line = null, ?Throwable $previous = null) {}
/** @var int */
protected $severity = E_ERROR;

public function __construct(
string $message = "",
int $code = 0,
int $severity = E_ERROR,
?string $filename = null,
?int $line = null,
?Throwable $previous = null
) {}

final public function getSeverity(): int {}
}

class Error implements Throwable
{
/** @var string */
protected $message = "";
/** @var string */
private $string = "";
/** @var int */
protected $code = 0;
/** @var string|null */
protected $file = null;
/** @var int|null */
protected $line = null;
/** @known */
private array $trace = [];
/** @known */
private ?Throwable $previous = null;

/** @implementation-alias Exception::__clone */
final private function __clone(): void {}

Expand Down Expand Up @@ -123,3 +166,7 @@ class ArithmeticError extends Error
class DivisionByZeroError extends ArithmeticError
{
}

class UnhandledMatchError extends Error
{
}
167 changes: 166 additions & 1 deletion Zend/zend_exceptions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3699b51b31e509c11435845c7e0d35a2608dd268 */
* Stub hash: fc90f59a8c670e7874f4a7564333c5b22c0eea5e */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -180,3 +180,168 @@ static const zend_function_entry class_ArithmeticError_methods[] = {
static const zend_function_entry class_DivisionByZeroError_methods[] = {
ZEND_FE_END
};


static const zend_function_entry class_UnhandledMatchError_methods[] = {
ZEND_FE_END
};

zend_class_entry *register_class_Throwable(zend_class_entry *class_entry_Stringable)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Throwable", class_Throwable_methods);
class_entry = zend_register_internal_interface(&ce);
zend_class_implements(class_entry, 1, class_entry_Stringable);

return class_entry;
}

zend_class_entry *register_class_Exception(zend_class_entry *class_entry_Throwable)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Exception", class_Exception_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
zend_class_implements(class_entry, 1, class_entry_Throwable);

zend_declare_property_string(class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PROTECTED);

zend_declare_property_string(class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE);

zend_declare_property_long(class_entry, "code", sizeof("code") - 1, 0, ZEND_ACC_PROTECTED);

zend_declare_property_null(class_entry, "file", sizeof("file") - 1, ZEND_ACC_PROTECTED);

zend_declare_property_null(class_entry, "line", sizeof("line") - 1, ZEND_ACC_PROTECTED);

zval property_trace_default_value;
ZVAL_EMPTY_ARRAY(&property_trace_default_value);
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));

zval property_previous_default_value;
ZVAL_NULL(&property_previous_default_value);
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));

return class_entry;
}

zend_class_entry *register_class_ErrorException(zend_class_entry *class_entry_Exception)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ErrorException", class_ErrorException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Exception);

return class_entry;
}

zend_class_entry *register_class_Error(zend_class_entry *class_entry_Throwable)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "Error", class_Error_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
zend_class_implements(class_entry, 1, class_entry_Throwable);

zend_declare_property_string(class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PROTECTED);

zend_declare_property_string(class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE);

zend_declare_property_long(class_entry, "code", sizeof("code") - 1, 0, ZEND_ACC_PROTECTED);

zend_declare_property_null(class_entry, "file", sizeof("file") - 1, ZEND_ACC_PROTECTED);

zend_declare_property_null(class_entry, "line", sizeof("line") - 1, ZEND_ACC_PROTECTED);

zval property_trace_default_value;
ZVAL_EMPTY_ARRAY(&property_trace_default_value);
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));

zval property_previous_default_value;
ZVAL_NULL(&property_previous_default_value);
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));

return class_entry;
}

zend_class_entry *register_class_CompileError(zend_class_entry *class_entry_Error)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "CompileError", class_CompileError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);

return class_entry;
}

zend_class_entry *register_class_ParseError(zend_class_entry *class_entry_CompileError)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ParseError", class_ParseError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_CompileError);

return class_entry;
}

zend_class_entry *register_class_TypeError(zend_class_entry *class_entry_Error)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "TypeError", class_TypeError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);

return class_entry;
}

zend_class_entry *register_class_ArgumentCountError(zend_class_entry *class_entry_TypeError)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ArgumentCountError", class_ArgumentCountError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_TypeError);

return class_entry;
}

zend_class_entry *register_class_ValueError(zend_class_entry *class_entry_Error)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ValueError", class_ValueError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);

return class_entry;
}

zend_class_entry *register_class_ArithmeticError(zend_class_entry *class_entry_Error)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "ArithmeticError", class_ArithmeticError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);

return class_entry;
}

zend_class_entry *register_class_DivisionByZeroError(zend_class_entry *class_entry_ArithmeticError)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "DivisionByZeroError", class_DivisionByZeroError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_ArithmeticError);

return class_entry;
}

zend_class_entry *register_class_UnhandledMatchError(zend_class_entry *class_entry_Error)
{
zend_class_entry ce, *class_entry;

INIT_CLASS_ENTRY(ce, "UnhandledMatchError", class_UnhandledMatchError_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Error);

return class_entry;
}

11 changes: 2 additions & 9 deletions Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,17 +1112,11 @@ zend_object_iterator *zend_generator_get_iterator(zend_class_entry *ce, zval *ob

void zend_register_generator_ce(void) /* {{{ */
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "Generator", class_Generator_methods);
zend_ce_generator = zend_register_internal_class(&ce);
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_ce_generator = register_class_Generator(zend_ce_iterator);
zend_ce_generator->create_object = zend_generator_create;
zend_ce_generator->serialize = zend_class_serialize_deny;
zend_ce_generator->unserialize = zend_class_unserialize_deny;

/* get_iterator has to be assigned *after* implementing the interface */
zend_class_implements(zend_ce_generator, 1, zend_ce_iterator);
zend_ce_generator->get_iterator = zend_generator_get_iterator;

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

INIT_CLASS_ENTRY(ce, "ClosedGeneratorException", NULL);
zend_ce_ClosedGeneratorException = zend_register_internal_class_ex(&ce, zend_ce_exception);
zend_ce_ClosedGeneratorException = register_class_ClosedGeneratorException(zend_ce_exception);
}
/* }}} */
10 changes: 9 additions & 1 deletion Zend/zend_generators.stub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

/** @generate-function-entries */
/**
* @generate-function-entries
* @generate-class-entries
*/

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

public function getReturn(): mixed {}
}

class ClosedGeneratorException extends Exception
{
}
Loading