Skip to content

Declare ext/reflection constants in stubs #9111

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

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 3 additions & 34 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include "zend_smart_str.h"
#include "zend_enum.h"
#include "zend_fibers.h"

#define REFLECTION_ATTRIBUTE_IS_INSTANCEOF (1 << 1)

#include "php_reflection_arginfo.h"

/* Key used to avoid leaking addresses in ReflectionProperty::getId() */
Expand Down Expand Up @@ -115,12 +118,6 @@ PHPAPI zend_class_entry *reflection_fiber_ptr;
target = intern->ptr; \
} while (0)

/* Class constants */
#define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \
zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (zend_long)value);

#define REFLECTION_ATTRIBUTE_IS_INSTANCEOF (1 << 1)

/* {{{ Object structure */

/* Struct for properties */
Expand Down Expand Up @@ -7135,8 +7132,6 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */
reflection_function_ptr = register_class_ReflectionFunction(reflection_function_abstract_ptr);
reflection_function_ptr->create_object = reflection_objects_new;

REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED);

reflection_generator_ptr = register_class_ReflectionGenerator();
reflection_generator_ptr->create_object = reflection_objects_new;

Expand All @@ -7158,42 +7153,18 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */
reflection_method_ptr = register_class_ReflectionMethod(reflection_function_abstract_ptr);
reflection_method_ptr->create_object = reflection_objects_new;

REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC);
REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC);
REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PROTECTED", ZEND_ACC_PROTECTED);
REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PRIVATE", ZEND_ACC_PRIVATE);
REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT);
REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_FINAL", ZEND_ACC_FINAL);

reflection_class_ptr = register_class_ReflectionClass(reflector_ptr);
reflection_class_ptr->create_object = reflection_objects_new;

/* IS_IMPLICIT_ABSTRACT is not longer used */
REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS);
REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL);
REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_READONLY", ZEND_ACC_READONLY_CLASS);

reflection_object_ptr = register_class_ReflectionObject(reflection_class_ptr);
reflection_object_ptr->create_object = reflection_objects_new;

reflection_property_ptr = register_class_ReflectionProperty(reflector_ptr);
reflection_property_ptr->create_object = reflection_objects_new;

REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC);
REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_READONLY", ZEND_ACC_READONLY);
REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC);
REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PROTECTED", ZEND_ACC_PROTECTED);
REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PRIVATE", ZEND_ACC_PRIVATE);

reflection_class_constant_ptr = register_class_ReflectionClassConstant(reflector_ptr);
reflection_class_constant_ptr->create_object = reflection_objects_new;

REGISTER_REFLECTION_CLASS_CONST_LONG(class_constant, "IS_PUBLIC", ZEND_ACC_PUBLIC);
REGISTER_REFLECTION_CLASS_CONST_LONG(class_constant, "IS_PROTECTED", ZEND_ACC_PROTECTED);
REGISTER_REFLECTION_CLASS_CONST_LONG(class_constant, "IS_PRIVATE", ZEND_ACC_PRIVATE);
REGISTER_REFLECTION_CLASS_CONST_LONG(class_constant, "IS_FINAL", ZEND_ACC_FINAL);

reflection_extension_ptr = register_class_ReflectionExtension(reflector_ptr);
reflection_extension_ptr->create_object = reflection_objects_new;

Expand All @@ -7218,8 +7189,6 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */
reflection_fiber_ptr = register_class_ReflectionFiber();
reflection_fiber_ptr->create_object = reflection_objects_new;

REGISTER_REFLECTION_CLASS_CONST_LONG(attribute, "IS_INSTANCEOF", REFLECTION_ATTRIBUTE_IS_INSTANCEOF);

REFLECTION_G(key_initialized) = 0;

return SUCCESS;
Expand Down
112 changes: 112 additions & 0 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public function getAttributes(?string $name = null, int $flags = 0): array {}

class ReflectionFunction extends ReflectionFunctionAbstract
{
/**
* @var int
* @cvalue ZEND_ACC_DEPRECATED
*/
public const IS_DEPRECATED = UNKNOWN;

public function __construct(Closure|string $function) {}

public function __toString(): string {}
Expand Down Expand Up @@ -161,6 +167,37 @@ public function getExecutingGenerator(): Generator {}

class ReflectionMethod extends ReflectionFunctionAbstract
{
/**
* @var int
* @cvalue ZEND_ACC_STATIC
*/
public const IS_STATIC = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PUBLIC
*/
public const IS_PUBLIC = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PROTECTED
*/
public const IS_PROTECTED = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PRIVATE
*/
public const IS_PRIVATE = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_ABSTRACT
*/
public const IS_ABSTRACT = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_FINAL
*/
public const IS_FINAL = UNKNOWN;

public string $class;

public function __construct(object|string $objectOrMethod, ?string $method = null) {}
Expand Down Expand Up @@ -215,6 +252,28 @@ public function setAccessible(bool $accessible): void {}
/** @not-serializable */
class ReflectionClass implements Reflector
{
/**
* @var int
* @cvalue ZEND_ACC_IMPLICIT_ABSTRACT_CLASS
* @todo deprecate
*/
public const IS_IMPLICIT_ABSTRACT = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
*/
public const IS_EXPLICIT_ABSTRACT = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_FINAL
*/
public const IS_FINAL = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_READONLY_CLASS
*/
public const IS_READONLY = UNKNOWN;

public string $name;

private function __clone(): void {}
Expand Down Expand Up @@ -391,6 +450,32 @@ public function __construct(object $object) {}
/** @not-serializable */
class ReflectionProperty implements Reflector
{
/**
* @var int
* @cvalue ZEND_ACC_STATIC
*/
public const IS_STATIC = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_READONLY
*/
public const IS_READONLY = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PUBLIC
*/
public const IS_PUBLIC = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PROTECTED
*/
public const IS_PROTECTED = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PRIVATE
*/
public const IS_PRIVATE = UNKNOWN;

public string $name;
public string $class;

Expand Down Expand Up @@ -461,6 +546,27 @@ public function getAttributes(?string $name = null, int $flags = 0): array {}
/** @not-serializable */
class ReflectionClassConstant implements Reflector
{
/**
* @var int
* @cvalue ZEND_ACC_PUBLIC
*/
public const IS_PUBLIC = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PROTECTED
*/
public const IS_PROTECTED = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_PRIVATE
*/
public const IS_PRIVATE = UNKNOWN;
/**
* @var int
* @cvalue ZEND_ACC_FINAL
*/
public const IS_FINAL = UNKNOWN;

public string $name;
public string $class;

Expand Down Expand Up @@ -704,6 +810,12 @@ private function __construct() {}
/** @not-serializable */
class ReflectionAttribute implements Reflector
{
/**
* @var int
* @cvalue REFLECTION_ATTRIBUTE_IS_INSTANCEOF
*/
public const IS_INSTANCEOF = UNKNOWN;

public function getName(): string {}
public function getTarget(): int {}
public function isRepeated(): bool {}
Expand Down
Loading