mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Support the #[\AllowDynamicProperties]
attribute in stubs (#8776)
* Support the `#[\AllowDynamicProperties]` attribute in stubs * Use `#[\AllowDynamicProperties]` attribute in stubs * Disallow applying both `@strict-properties` and `#[\AllowDynamicProperties]`
This commit is contained in:
parent
68c234332c
commit
ff472ce6fc
4 changed files with 34 additions and 3 deletions
|
@ -38,8 +38,6 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
|
||||||
zend_register_default_classes();
|
zend_register_default_classes();
|
||||||
|
|
||||||
zend_standard_class_def = register_class_stdClass();
|
zend_standard_class_def = register_class_stdClass();
|
||||||
zend_add_class_attribute(zend_standard_class_def, zend_ce_allow_dynamic_properties->name, 0);
|
|
||||||
zend_standard_class_def->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
/** @generate-class-entries */
|
/** @generate-class-entries */
|
||||||
|
|
||||||
|
#[\AllowDynamicProperties]
|
||||||
class stdClass
|
class stdClass
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
4
Zend/zend_builtin_functions_arginfo.h
generated
4
Zend/zend_builtin_functions_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
||||||
/* This is a generated file, edit the .stub.php file instead.
|
/* This is a generated file, edit the .stub.php file instead.
|
||||||
* Stub hash: 33a976db268b72cee985011198125f652bc6c86d */
|
* Stub hash: 80355bb52d643177e3a661a515d9ea915bd1e2fc */
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
|
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
|
@ -353,6 +353,8 @@ static zend_class_entry *register_class_stdClass(void)
|
||||||
|
|
||||||
INIT_CLASS_ENTRY(ce, "stdClass", class_stdClass_methods);
|
INIT_CLASS_ENTRY(ce, "stdClass", class_stdClass_methods);
|
||||||
class_entry = zend_register_internal_class_ex(&ce, NULL);
|
class_entry = zend_register_internal_class_ex(&ce, NULL);
|
||||||
|
class_entry->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
|
||||||
|
zend_add_class_attribute(class_entry, zend_ce_allow_dynamic_properties->name, 0);
|
||||||
|
|
||||||
return class_entry;
|
return class_entry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2273,6 +2273,8 @@ class ClassInfo {
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
public $isStrictProperties;
|
public $isStrictProperties;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
public $allowsDynamicProperties;
|
||||||
|
/** @var bool */
|
||||||
public $isNotSerializable;
|
public $isNotSerializable;
|
||||||
/** @var Name[] */
|
/** @var Name[] */
|
||||||
public $extends;
|
public $extends;
|
||||||
|
@ -2305,6 +2307,7 @@ class ClassInfo {
|
||||||
?SimpleType $enumBackingType,
|
?SimpleType $enumBackingType,
|
||||||
bool $isDeprecated,
|
bool $isDeprecated,
|
||||||
bool $isStrictProperties,
|
bool $isStrictProperties,
|
||||||
|
bool $allowsDynamicProperties,
|
||||||
bool $isNotSerializable,
|
bool $isNotSerializable,
|
||||||
array $extends,
|
array $extends,
|
||||||
array $implements,
|
array $implements,
|
||||||
|
@ -2321,6 +2324,7 @@ class ClassInfo {
|
||||||
$this->enumBackingType = $enumBackingType;
|
$this->enumBackingType = $enumBackingType;
|
||||||
$this->isDeprecated = $isDeprecated;
|
$this->isDeprecated = $isDeprecated;
|
||||||
$this->isStrictProperties = $isStrictProperties;
|
$this->isStrictProperties = $isStrictProperties;
|
||||||
|
$this->allowsDynamicProperties = $allowsDynamicProperties;
|
||||||
$this->isNotSerializable = $isNotSerializable;
|
$this->isNotSerializable = $isNotSerializable;
|
||||||
$this->extends = $extends;
|
$this->extends = $extends;
|
||||||
$this->implements = $implements;
|
$this->implements = $implements;
|
||||||
|
@ -2409,6 +2413,10 @@ class ClassInfo {
|
||||||
$code .= $property->getDeclaration($allConstInfos);
|
$code .= $property->getDeclaration($allConstInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->allowsDynamicProperties) {
|
||||||
|
$code .= "\tzend_add_class_attribute(class_entry, zend_ce_allow_dynamic_properties->name, 0);\n";
|
||||||
|
}
|
||||||
|
|
||||||
if ($attributeInitializationCode = generateAttributeInitialization($this->funcInfos, $this->cond)) {
|
if ($attributeInitializationCode = generateAttributeInitialization($this->funcInfos, $this->cond)) {
|
||||||
$code .= "\n" . $attributeInitializationCode;
|
$code .= "\n" . $attributeInitializationCode;
|
||||||
}
|
}
|
||||||
|
@ -2452,6 +2460,10 @@ class ClassInfo {
|
||||||
$flags[] = "ZEND_ACC_NO_DYNAMIC_PROPERTIES";
|
$flags[] = "ZEND_ACC_NO_DYNAMIC_PROPERTIES";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->allowsDynamicProperties) {
|
||||||
|
$flags[] = "ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES";
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isNotSerializable) {
|
if ($this->isNotSerializable) {
|
||||||
$flags[] = "ZEND_ACC_NOT_SERIALIZABLE";
|
$flags[] = "ZEND_ACC_NOT_SERIALIZABLE";
|
||||||
}
|
}
|
||||||
|
@ -3273,6 +3285,7 @@ function parseClass(
|
||||||
$isDeprecated = false;
|
$isDeprecated = false;
|
||||||
$isStrictProperties = false;
|
$isStrictProperties = false;
|
||||||
$isNotSerializable = false;
|
$isNotSerializable = false;
|
||||||
|
$allowsDynamicProperties = false;
|
||||||
|
|
||||||
if ($comment) {
|
if ($comment) {
|
||||||
$tags = parseDocComment($comment);
|
$tags = parseDocComment($comment);
|
||||||
|
@ -3289,6 +3302,22 @@ function parseClass(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($class->attrGroups as $attrGroup) {
|
||||||
|
foreach ($attrGroup->attrs as $attr) {
|
||||||
|
switch ($attr->name->toCodeString()) {
|
||||||
|
case '\\AllowDynamicProperties':
|
||||||
|
$allowsDynamicProperties = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Unhandled attribute {$attr->name->toCodeString()}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isStrictProperties && $allowsDynamicProperties) {
|
||||||
|
throw new Exception("A class may not have '@strict-properties' and '#[\\AllowDynamicProperties]' at the same time.");
|
||||||
|
}
|
||||||
|
|
||||||
$extends = [];
|
$extends = [];
|
||||||
$implements = [];
|
$implements = [];
|
||||||
|
|
||||||
|
@ -3319,6 +3348,7 @@ function parseClass(
|
||||||
? SimpleType::fromNode($class->scalarType) : null,
|
? SimpleType::fromNode($class->scalarType) : null,
|
||||||
$isDeprecated,
|
$isDeprecated,
|
||||||
$isStrictProperties,
|
$isStrictProperties,
|
||||||
|
$allowsDynamicProperties,
|
||||||
$isNotSerializable,
|
$isNotSerializable,
|
||||||
$extends,
|
$extends,
|
||||||
$implements,
|
$implements,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue