diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index a52e8ebdea9f..cef1c6e7f5a5 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -200,8 +200,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr if (!is_array($objectOrArray)) { if (!$objectOrArray instanceof \Traversable) { throw new NoSuchIndexException(sprintf( - 'Cannot read property "%s".', - $property + 'Cannot read index "%s" while trying to traverse path "%s".', + $property, + (string) $propertyPath )); } @@ -209,8 +210,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr } throw new NoSuchIndexException(sprintf( - 'Cannot read property "%s". Available properties are "%s"', + 'Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, + (string) $propertyPath, print_r(array_keys($objectOrArray), true) )); } @@ -250,7 +252,7 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr private function &readIndex(&$array, $index) { if (!$array instanceof \ArrayAccess && !is_array($array)) { - throw new NoSuchIndexException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array))); + throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_class($array))); } // Use an array instead of an object since performance is very crucial here @@ -294,7 +296,7 @@ private function &readProperty(&$object, $property) ); if (!is_object($object)) { - throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you should write the property path as "[%s]" instead?', $property, $property)); + throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%s]" instead.', $property, $property)); } $camelized = $this->camelize($property); @@ -364,7 +366,7 @@ private function &readProperty(&$object, $property) private function writeIndex(&$array, $index, $value) { if (!$array instanceof \ArrayAccess && !is_array($array)) { - throw new NoSuchIndexException(sprintf('Index "%s" cannot be modified in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array))); + throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array))); } $array[$index] = $value; diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php b/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php index 738e5062fda0..fc8ac4ed2dd4 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php @@ -12,7 +12,7 @@ namespace Symfony\Component\PropertyAccess; /** - * A configurable builder for PropertyAccessorInterface objects. + * A configurable builder to create a PropertyAccessor. * * @author Jérémie Augustin */ @@ -53,7 +53,7 @@ public function disableMagicCall() } /** - * @return bool true if the use of "__call" by the PropertyAccessor is enabled + * @return bool whether the use of "__call" by the PropertyAccessor is enabled */ public function isMagicCallEnabled() { @@ -61,7 +61,10 @@ public function isMagicCallEnabled() } /** - * Enables exceptions in read context for array by PropertyAccessor + * Enables exceptions when reading a non-existing index. + * + * This has no influence on writing non-existing indices with PropertyAccessorInterface::setValue() + * which are always created on-the-fly. * * @return PropertyAccessorBuilder The builder object */ @@ -73,7 +76,9 @@ public function enableExceptionOnInvalidIndex() } /** - * Disables exceptions in read context for array by PropertyAccessor + * Disables exceptions when reading a non-existing index. + * + * Instead, null is returned when calling PropertyAccessorInterface::getValue() on a non-existing index. * * @return PropertyAccessorBuilder The builder object */ @@ -85,7 +90,7 @@ public function disableExceptionOnInvalidIndex() } /** - * @return bool true is exceptions in read context for array is enabled + * @return bool whether an exception is thrown or null is returned when reading a non-existing index */ public function isExceptionOnInvalidIndexEnabled() { @@ -93,9 +98,9 @@ public function isExceptionOnInvalidIndexEnabled() } /** - * Builds and returns a new propertyAccessor object. + * Builds and returns a new PropertyAccessor object. * - * @return PropertyAccessorInterface The built propertyAccessor + * @return PropertyAccessorInterface The built PropertyAccessor */ public function getPropertyAccessor() {