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

Appearance settings

Commit c071743

Browse filesBrowse files
committed
Fix Usage with anonymous classes
Replace 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
1 parent 40beab4 commit c071743
Copy full SHA for c071743

File tree

Expand file treeCollapse file tree

2 files changed

+72
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+72
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/PropertyAccessor.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private function readProperty($zval, $property)
523523
*/
524524
private function getReadAccessInfo($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
private function getWriteAccessInfo($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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,74 @@ public function testThrowTypeErrorWithInterface()
578578

579579
$this->propertyAccessor->setValue($object, 'countable', 'This is a string, \Countable expected.');
580580
}
581+
582+
583+
public function testAnonymousClassRead()
584+
{
585+
if (PHP_MAJOR_VERSION < 7) {
586+
$this->markTestSkipped('Anonymous Classes are only supported on PHP7');
587+
588+
return;
589+
}
590+
591+
$value = 'bar';
592+
593+
$obj = $this->generateAnonymousClass($value);
594+
595+
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
596+
597+
$this->assertEquals($value, $propertyAccessor->getValue($obj, 'foo'));
598+
}
599+
600+
public function testAnonymousClassWrite()
601+
{
602+
if (PHP_MAJOR_VERSION < 7) {
603+
$this->markTestSkipped('Anonymous Classes are only supported on PHP7');
604+
605+
return;
606+
}
607+
608+
$value = 'bar';
609+
610+
$obj = $this->generateAnonymousClass('');
611+
612+
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
613+
$propertyAccessor->setValue($obj, 'foo', $value);
614+
615+
$this->assertEquals($value, $propertyAccessor->getValue($obj, 'foo'));
616+
}
617+
618+
/**
619+
* @param $value
620+
*/
621+
private function generateAnonymousClass($value)
622+
{
623+
$obj = eval('return new class($value)
624+
{
625+
private $foo;
626+
627+
public function __construct($foo)
628+
{
629+
$this->foo = $foo;
630+
}
631+
632+
/**
633+
* @return mixed
634+
*/
635+
public function getFoo()
636+
{
637+
return $this->foo;
638+
}
639+
640+
/**
641+
* @param mixed $foo
642+
*/
643+
public function setFoo($foo)
644+
{
645+
$this->foo = $foo;
646+
}
647+
};');
648+
649+
return $obj;
650+
}
581651
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.