8000 Merge branch '5.1' · symfony/symfony@0885ebb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0885ebb

Browse files
committed
Merge branch '5.1'
* 5.1: Revert "bug #37622 [PropertyAccess] Fix accessing dynamic properties (andreyserdjuk)"
2 parents 45329ab + 47b9b5c commit 0885ebb

File tree

3 files changed

+4
-45
lines changed

3 files changed

+4
-45
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,10 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
450450

451451
throw $e;
452452
}
453-
} elseif (property_exists($object, $property)) {
454-
try {
455-
$result[self::VALUE] = $object->$property;
456-
if (isset($zval[self::REF])) {
457-
$result[self::REF] = &$object->$property;
458-
}
459-
} catch (\Error $e) {
460-
if (!$ignoreInvalidProperty) {
461-
throw new NoSuchPropertyException(sprintf('Can\'t read protected or private property "%s" in class "%s".', $property, $class), 0, $e);
462-
}
453+
} elseif ($object instanceof \stdClass && property_exists($object, $property)) {
454+
$result[self::VALUE] = $object->$property;
455+
if (isset($zval[self::REF])) {
456+
$result[self::REF] = &$object->$property;
463457
}
464458
} elseif (!$ignoreInvalidProperty) {
465459
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));

src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClassDynamicProperty.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength;
2323
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidMethods;
2424
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClass;
25-
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassDynamicProperty;
2625
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassIsWritable;
2726
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicCall;
2827
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet;
@@ -99,29 +98,6 @@ public function testGetValue($objectOrArray, $path, $value)
9998
$this->assertSame($value, $this->propertyAccessor->getValue($objectOrArray, $path));
10099
}
101100

102-
/**
103-
* Test get dynamic value from object is other than \stdClass instance.
104-
*/
105-
public function testGetDynamicValue()
106-
{
107-
$value = 'dynamicPropertyValue';
108-
$path = 'dynamicProperty';
109-
$object = new TestClassDynamicProperty($value);
110-
111-
$this->assertSame($value, $this->propertyAccessor->getValue($object, $path));
112-
}
113-
114-
/**
115-
* Ensure exact exception with message was thrown on access to non-public property.
116-
*/
117-
public function testGetInaccessibleProperty()
118-
{
119-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
120-
$this->expectExceptionMessage(sprintf('Can\'t read protected or private property "%s" in class "%s".', 'protectedProperty', TestClass::class));
121-
122-
$this->propertyAccessor->getValue(new TestClass('Bernhard'), 'protectedProperty');
123-
}
124-
125101
/**
126102
* @dataProvider getPathsWithMissingProperty
127103
*/

0 commit comments

Comments
 (0)
0