Revert "bug #37622 [PropertyAccess] Fix accessing dynamic properties (andreyserdjuk)"
This reverts commit92cb709222
, reversing changes made tofc3095ff2f
.
This commit is contained in:
parent
c367e26e3e
commit
47b9b5cf21
@ -435,16 +435,10 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
|
||||
throw $e;
|
||||
}
|
||||
} elseif (property_exists($object, $property)) {
|
||||
try {
|
||||
$result[self::VALUE] = $object->$property;
|
||||
if (isset($zval[self::REF])) {
|
||||
$result[self::REF] = &$object->$property;
|
||||
}
|
||||
} catch (\Error $e) {
|
||||
if (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(sprintf('Can\'t read protected or private property "%s" in class "%s".', $property, $class), 0, $e);
|
||||
}
|
||||
} elseif ($object instanceof \stdClass && property_exists($object, $property)) {
|
||||
$result[self::VALUE] = $object->$property;
|
||||
if (isset($zval[self::REF])) {
|
||||
$result[self::REF] = &$object->$property;
|
||||
}
|
||||
} elseif (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
class TestClassDynamicProperty
|
||||
{
|
||||
public function __construct($dynamicProperty)
|
||||
{
|
||||
$this->dynamicProperty = $dynamicProperty;
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ use Symfony\Component\PropertyAccess\Tests\Fixtures\ReturnTyped;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidMethods;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClass;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassDynamicProperty;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassIsWritable;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicCall;
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet;
|
||||
@ -98,29 +97,6 @@ class PropertyAccessorTest extends TestCase
|
||||
$this->assertSame($value, $this->propertyAccessor->getValue($objectOrArray, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get dynamic value from object is other than \stdClass instance.
|
||||
*/
|
||||
public function testGetDynamicValue()
|
||||
{
|
||||
$value = 'dynamicPropertyValue';
|
||||
$path = 'dynamicProperty';
|
||||
$object = new TestClassDynamicProperty($value);
|
||||
|
||||
$this->assertSame($value, $this->propertyAccessor->getValue($object, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure exact exception with message was thrown on access to non-public property.
|
||||
*/
|
||||
public function testGetInaccessibleProperty()
|
||||
{
|
||||
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
|
||||
$this->expectExceptionMessage(sprintf('Can\'t read protected or private property "%s" in class "%s".', 'protectedProperty', TestClass::class));
|
||||
|
||||
$this->propertyAccessor->getValue(new TestClass('Bernhard'), 'protectedProperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPathsWithMissingProperty
|
||||
*/
|
||||
|
Reference in New Issue
Block a user