fix(stub): remove pseudo-type aliases that could rewrite property names

- Removed "any", "box", and "stream" aliases mapping to ZEND_STR_MIXED
- Added test case to verify property names are not rewritten through pseudo-type string aliases
- Created attribute metadata test to ensure string arguments maintain original values
- Prevented potential conflicts between pseudo-type aliases and actual property/argument names
master
韩天峰 2 weeks ago
parent a536172f82
commit 5162261c75
  1. 3
      src/gen_stub.php
  2. 42
      tests/compiler/attribute/pseudo-type-string-metadata.phpt
  3. 101
      tests/compiler/object_property/property-known-string-names.phpt

@ -3125,9 +3125,6 @@ class StringBuilder {
"false" => "ZEND_STR_FALSE",
"null" => "ZEND_STR_NULL_LOWERCASE",
"mixed" => "ZEND_STR_MIXED",
"any" => "ZEND_STR_MIXED",
"box" => "ZEND_STR_MIXED",
"stream" => "ZEND_STR_MIXED",
];
// NEW in 8.1

@ -0,0 +1,42 @@
--TEST--
attribute strings must not be rewritten through pseudo-type aliases
--FILE--
<?php
#[Attribute(Attribute::TARGET_CLASS)]
final class StringMetadata
{
public function __construct(
public string $stream,
public string $any,
public string $box,
) {
}
}
#[StringMetadata(stream: 'stream', any: 'any', box: 'box')]
final class AttributedClass
{
}
function main(): void
{
$attribute = (new ReflectionClass(AttributedClass::class))->getAttributes()[0];
var_dump($attribute->getArguments());
$metadata = $attribute->newInstance();
var_dump($metadata->stream, $metadata->any, $metadata->box);
}
?>
--EXPECT--
array(3) {
["stream"]=>
string(6) "stream"
["any"]=>
string(3) "any"
["box"]=>
string(3) "box"
}
string(6) "stream"
string(3) "any"
string(3) "box"

@ -0,0 +1,101 @@
--TEST--
property names must not be rewritten through pseudo-type string aliases
--FILE--
<?php
final class KnownStringProperties
{
private mixed $mixed = 'mixed';
private mixed $stream = 'initial-stream';
private mixed $any = 'initial-any';
private mixed $box = 'initial-box';
private mixed $int = 42;
private mixed $string = 'string';
private mixed $handleStream = 'camel-case';
public function update(): void
{
$this->stream = 'updated-stream';
$this->any = 'updated-any';
$this->box = 'updated-box';
}
public function values(): array
{
return [
$this->mixed,
$this->stream,
$this->any,
$this->box,
$this->int,
$this->string,
$this->handleStream,
];
}
}
function main(): void
{
$object = new KnownStringProperties();
var_dump($object->values());
$object->update();
var_dump($object->values());
$reflection = new ReflectionClass(KnownStringProperties::class);
$names = array_map(
static fn (ReflectionProperty $property): string => $property->getName(),
$reflection->getProperties(),
);
sort($names);
var_dump($names);
}
?>
--EXPECT--
array(7) {
[0]=>
string(5) "mixed"
[1]=>
string(14) "initial-stream"
[2]=>
string(11) "initial-any"
[3]=>
string(11) "initial-box"
[4]=>
int(42)
[5]=>
string(6) "string"
[6]=>
string(10) "camel-case"
}
array(7) {
[0]=>
string(5) "mixed"
[1]=>
string(14) "updated-stream"
[2]=>
string(11) "updated-any"
[3]=>
string(11) "updated-box"
[4]=>
int(42)
[5]=>
string(6) "string"
[6]=>
string(10) "camel-case"
}
array(7) {
[0]=>
string(3) "any"
[1]=>
string(3) "box"
[2]=>
string(12) "handleStream"
[3]=>
string(3) "int"
[4]=>
string(5) "mixed"
[5]=>
string(6) "stream"
[6]=>
string(6) "string"
}
Loading…
Cancel
Save