Skip to content

Commit 69e392e

Browse files
committed
Allow ZEND_ACC_VIRTUAL to be used to not have property backing storage without resorting to hooks
This is useful to reduce the memory usage of objects that don't actually use the backing storage. Examples are XMLReader and DOM. When the properties were added to the stubs, these objects became much much bigger, which is a waste of memory. Closes GH-11644. Work towards GH-13988.
1 parent 76ad89c commit 69e392e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

build/gen_stub.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,7 @@ class PropertyInfo extends VariableLike
29072907
public ?Expr $defaultValue;
29082908
public ?string $defaultValueString;
29092909
public bool $isDocReadonly;
2910+
public bool $isVirtual;
29102911

29112912
/**
29122913
* @var AttributeInfo[] $attributes
@@ -2920,6 +2921,7 @@ public function __construct(
29202921
?Expr $defaultValue,
29212922
?string $defaultValueString,
29222923
bool $isDocReadonly,
2924+
bool $isVirtual,
29232925
?string $link,
29242926
?int $phpVersionIdMinimumCompatibility,
29252927
array $attributes,
@@ -2930,6 +2932,7 @@ public function __construct(
29302932
$this->defaultValue = $defaultValue;
29312933
$this->defaultValueString = $defaultValueString;
29322934
$this->isDocReadonly = $isDocReadonly;
2935+
$this->isVirtual = $isVirtual;
29332936
parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment);
29342937
}
29352938

@@ -3045,6 +3048,10 @@ protected function getFlagsByPhpVersion(): array
30453048
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_READONLY", PHP_82_VERSION_ID);
30463049
}
30473050

3051+
if ($this->isVirtual) {
3052+
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_VIRTUAL", PHP_84_VERSION_ID);
3053+
}
3054+
30483055
return $flags;
30493056
}
30503057

@@ -4424,6 +4431,7 @@ function parseProperty(
44244431
): PropertyInfo {
44254432
$phpDocType = null;
44264433
$isDocReadonly = false;
4434+
$isVirtual = false;
44274435
$link = null;
44284436

44294437
if ($comments) {
@@ -4435,6 +4443,8 @@ function parseProperty(
44354443
$isDocReadonly = true;
44364444
} elseif ($tag->name === 'link') {
44374445
$link = $tag->value;
4446+
} elseif ($tag->name === 'virtual') {
4447+
$isVirtual = true;
44384448
}
44394449
}
44404450
}
@@ -4463,6 +4473,7 @@ function parseProperty(
44634473
$property->default,
44644474
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
44654475
$isDocReadonly,
4476+
$isVirtual,
44664477
$link,
44674478
$phpVersionIdMinimumCompatibility,
44684479
$attributes,

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6041,7 +6041,7 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
60416041
}
60426042

60436043
/* Get-only virtual property can never be written to. */
6044-
if ((prop->flags & ZEND_ACC_VIRTUAL) && !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
6044+
if (prop->hooks && (prop->flags & ZEND_ACC_VIRTUAL) && !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
60456045
zend_type never_type = ZEND_TYPE_INIT_CODE(IS_NEVER, 0, 0);
60466046
reflection_type_factory(never_type, return_value, 0);
60476047
return;

0 commit comments

Comments
 (0)