Closed
Description
When you call getValue() with an array and a nested propertyPath that does not exists, the PropertyAccess creates the Index of the first path entry in the given array.
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
include '../vendor/autoload.php';
$arrayCollection = new \Doctrine\Common\Collections\ArrayCollection();
if ($arrayCollection->containsKey('google')) {
echo 'index google exists';
} else {
echo 'index google NOT exists';
}
echo "\n";
if ($arrayCollection->containsKey('facebook')) {
echo 'index facebook exists';
} else {
echo 'index facebook NOT exists';
}
echo "\n";
echo "\n";
$propertyAccessor = PropertyAccess::createPropertyAccessor();
echo "call getValue with propertyPath [google]\n";
$propertyAccessor->getValue($arrayCollection, '[google]');
echo "call getValue with propertyPath [facebook][admin]\n";
$propertyAccessor->getValue($arrayCollection, '[facebook][admin]');
echo "\n";
if ($arrayCollection->containsKey('google')) {
echo 'index google exists';
} else {
echo 'index google NOT exists';
}
echo "\n";
if ($arrayCollection->containsKey('facebook')) {
echo 'index facebook exists';
} else {
echo 'index facebook NOT exists';
}
With that code we get the following output:
index google NOT exists
index facebook NOT exists
call getValue with propertyPath [google]
call getValue with propertyPath [facebook][admin]
index google NOT exists
index facebook exists
I think a "read function" should never change/modify the object/array that it reads from.