Skip to content

Commit f78d5cf

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 606eb84 commit f78d5cf

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
@@ -2916,6 +2916,7 @@ class PropertyInfo extends VariableLike
29162916
public ?Expr $defaultValue;
29172917
public ?string $defaultValueString;
29182918
public bool $isDocReadonly;
2919+
public bool $isVirtual;
29192920

29202921
/**
29212922
* @var AttributeInfo[] $attributes
@@ -2929,6 +2930,7 @@ public function __construct(
29292930
?Expr $defaultValue,
29302931
?string $defaultValueString,
29312932
bool $isDocReadonly,
2933+
bool $isVirtual,
29322934
?string $link,
29332935
?int $phpVersionIdMinimumCompatibility,
29342936
array $attributes,
@@ -2939,6 +2941,7 @@ public function __construct(
29392941
$this->defaultValue = $defaultValue;
29402942
$this->defaultValueString = $defaultValueString;
29412943
$this->isDocReadonly = $isDocReadonly;
2944+
$this->isVirtual = $isVirtual;
29422945
parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment);
29432946
}
29442947

@@ -3054,6 +3057,10 @@ protected function getFlagsByPhpVersion(): array
30543057
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_READONLY", PHP_82_VERSION_ID);
30553058
}
30563059

3060+
if ($this->isVirtual) {
3061+
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_VIRTUAL", PHP_84_VERSION_ID);
3062+
}
3063+
30573064
return $flags;
30583065
}
30593066

@@ -4454,6 +4461,7 @@ function parseProperty(
44544461
): PropertyInfo {
44554462
$phpDocType = null;
44564463
$isDocReadonly = false;
4464+
$isVirtual = false;
44574465
$link = null;
44584466

44594467
if ($comments) {
@@ -4465,6 +4473,8 @@ function parseProperty(
44654473
$isDocReadonly = true;
44664474
} elseif ($tag->name === 'link') {
44674475
$link = $tag->value;
4476+
} elseif ($tag->name === 'virtual') {
4477+
$isVirtual = true;
44684478
}
44694479
}
44704480
}
@@ -4493,6 +4503,7 @@ function parseProperty(
44934503
$property->default,
44944504
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
44954505
$isDocReadonly,
4506+
$isVirtual,
44964507
$link,
44974508
$phpVersionIdMinimumCompatibility,
44984509
$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)