- 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 namesmaster
parent
a536172f82
commit
5162261c75
3 changed files with 143 additions and 3 deletions
@ -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…
Reference in new issue