Repository navigation
fix(property): an offset write initializes an uninitialized array property - #14358
Conversation
…perty vimeo#14272 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
✅ Performance: unchanged · Types: decreased
How to read this table
✅ symfony: issues +0 −1Memory 3 600 → 3 600 MB (<0.1 %) · Wall 265.4 → 264.6 s (−0.3 %) Weighted 98 405 → 98 398 (−7, −0.01 %): L7 −1
Removed (1)
✅ drupal: issues +0 −11Memory 4 841 → 4 841 MB (<0.1 %) · Wall 190.4 → 193.6 s (+1.7 %) Weighted 169 293 → 169 236 (−57, −0.03 %): L2 −4 · L7 −7
Removed (11)
head d6885a7 · base 3a3fdf6 (merge-base) · workflow run |
# Conflicts: # tests/PropertyTypeTest.php
orklah
left a comment
There was a problem hiding this comment.
Thanks! The offset write is now accepted in the constructor, but the exemption also covers native
readonly properties, where PHP throws instead of creating the array:
final class Bag
{
/** @var array<string, string> */
public readonly array $values;
public function __construct(string $name)
{
$this->values["name"] = $name; // Error: Cannot indirectly modify readonly property Bag::$values
}
}master reports UninitializedProperty + PropertyNotSetInConstructor here; this PR reports nothing (same
with a readonly class). Excluding natively readonly properties fixes it:
|| ($in_assignment
&& $stmt_type->isArray()
&& $codebase->properties->hasStorage($property_id)
&& !$codebase->properties->getStorage($property_id)->native_readonly
)Could you add that, with this case to providerInvalidCodeParse:
'offsetWriteToAnUninitializedReadonlyArrayProperty' => [
'code' => '<?php
final class Bag
{
/** @var array<string, string> */
public readonly array $values;
public function __construct(string $name)
{
$this->values["name"] = $name;
}
}',
'error_message' => 'UninitializedProperty',
'error_levels' => [],
'php_version' => '8.1',
],and, to pin the boundaries, valid cases for $this->values[] = $x; and $this->values["a"]["b"] = $x;,
plus an invalid case for $this->values["a"] .= "x"; (a read-modify-write, which PHP rejects on an
uninitialized property)?
…roperty PHP throws for an offset write to an uninitialized native readonly property instead of creating the array, so the exemption of an uninitialized array property leaves those out. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Pushed d6885a7. The exemption leaves natively readonly properties out ( |
Writing an offset of an uninitialized typed array property in the constructor is reported as
UninitializedPropertyandPropertyNotSetInConstructor, although PHP creates the array on the write.Before
After
Fixes #14272