Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getValue($objectOrArray, $propertyPath)
self::VALUE => $objectOrArray,
];

if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
return $this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty)[self::VALUE];
}

Expand All @@ -166,7 +166,7 @@ public function getValue($objectOrArray, $propertyPath)
*/
public function setValue(&$objectOrArray, $propertyPath, $value)
{
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
$zval = [
self::VALUE => $objectOrArray,
];
Expand Down Expand Up @@ -293,7 +293,13 @@ public function isReadable($objectOrArray, $propertyPath)
$zval = [
self::VALUE => $objectOrArray,
];
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);

// handle stdClass with properties with a dot in the name
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
} else {
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
}

return true;
} catch (AccessException $e) {
Expand All @@ -314,6 +320,14 @@ public function isWritable($objectOrArray, $propertyPath)
$zval = [
self::VALUE => $objectOrArray,
];

// handle stdClass with properties with a dot in the name
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);

return true;
}

$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);

for ($i = \count($propertyValues) - 1; 0 <= $i; --$i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ public static function getValidPropertyPaths()
[['firstName' => 'Bernhard'], '[firstName]', 'Bernhard'],
[['index' => ['firstName' => 'Bernhard']], '[index][firstName]', 'Bernhard'],
[(object) ['firstName' => 'Bernhard'], 'firstName', 'Bernhard'],
[(object) ['first.Name' => 'Bernhard'], 'first.Name', 'Bernhard'],
[(object) ['property' => ['firstName' => 'Bernhard']], 'property[firstName]', 'Bernhard'],
[['index' => (object) ['firstName' => 'Bernhard']], '[index].firstName', 'Bernhard'],
[(object) ['property' => (object) ['firstName' => 'Bernhard']], 'property.firstName', 'Bernhard'],
Expand Down