Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa94dd6

Browse files
committed
bug#23156 [PropertyAccess] Fix Usage with anonymous classes (mablae)
This PR was merged into the 3.2 branch.Discussion----------[PropertyAccess] Fix Usage with anonymous classes| Q | A| ------------- | ---| Branch? | 3.2| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#23136| License | MITReplace forbidden characters in the the class names of Anonymous Classes in form of"class@anonymous /symfony/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php0x7f3f5f267ad5"Wrapped in eval to avoid PHP parsing errors < 7 and using `rawurlenceode` for perf reasonsThanks@nicolas-grekas for the help and patience. Let me know if anything is missing.Commits-------3f7fd43 Fix Usage with anonymous classes
2 parentsc0486f6 +3f7fd43 commitaa94dd6

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

‎src/Symfony/Component/PropertyAccess/PropertyAccessor.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private function readProperty($zval, $property)
523523
*/
524524
privatefunctiongetReadAccessInfo($class,$property)
525525
{
526-
$key =$class.'..'.$property;
526+
$key =(false !==strpos($class,'@') ?rawurlencode($class) :$class).'..'.$property;
527527

528528
if (isset($this->readPropertyCache[$key])) {
529529
return$this->readPropertyCache[$key];
@@ -702,7 +702,7 @@ private function writeCollection($zval, $property, $collection, $addMethod, $rem
702702
*/
703703
privatefunctiongetWriteAccessInfo($class,$property,$value)
704704
{
705-
$key =$class.'..'.$property;
705+
$key =(false !==strpos($class,'@') ?rawurlencode($class) :$class).'..'.$property;
706706

707707
if (isset($this->writePropertyCache[$key])) {
708708
return$this->writePropertyCache[$key];

‎src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,64 @@ public function testThrowTypeErrorWithInterface()
578578

579579
$this->propertyAccessor->setValue($object,'countable','This is a string, \Countable expected.');
580580
}
581+
582+
/**
583+
* @requires PHP 7.0
584+
*/
585+
publicfunctiontestAnonymousClassRead()
586+
{
587+
$value ='bar';
588+
589+
$obj =$this->generateAnonymousClass($value);
590+
591+
$propertyAccessor =newPropertyAccessor(false,false,newArrayAdapter());
592+
593+
$this->assertEquals($value,$propertyAccessor->getValue($obj,'foo'));
594+
}
595+
596+
/**
597+
* @requires PHP 7.0
598+
*/
599+
publicfunctiontestAnonymousClassWrite()
600+
{
601+
$value ='bar';
602+
603+
$obj =$this->generateAnonymousClass('');
604+
605+
$propertyAccessor =newPropertyAccessor(false,false,newArrayAdapter());
606+
$propertyAccessor->setValue($obj,'foo',$value);
607+
608+
$this->assertEquals($value,$propertyAccessor->getValue($obj,'foo'));
609+
}
610+
611+
privatefunctiongenerateAnonymousClass($value)
612+
{
613+
$obj =eval('return new class($value)
614+
{
615+
private $foo;
616+
617+
public function __construct($foo)
618+
{
619+
$this->foo = $foo;
620+
}
621+
622+
/**
623+
* @return mixed
624+
*/
625+
public function getFoo()
626+
{
627+
return $this->foo;
628+
}
629+
630+
/**
631+
* @param mixed $foo
632+
*/
633+
public function setFoo($foo)
634+
{
635+
$this->foo = $foo;
636+
}
637+
};');
638+
639+
return$obj;
640+
}
581641
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp