Bug #62553
closedException when accessing empty ObjectStorage property via numeric index
100%
Description
Imagine a snippet like this within a Fluid template:
{product.images.0.title}
Given the images
property is an ObjectStorage
and empty, a warning exception is thrown:
#1: PHP Warning: spl_object_hash() expects parameter 1 to be object, string given in /var/www/typo3_src/typo3/sysext/extbase/Classes/Persistence/ObjectStorage.php line 160
This is caused by the following steps:
- Fluid parser calls
\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::getPropertyPath
- The property "0" is not found via
\TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyInternal
- The array check yields
TRUE
(ObjectStorage
implements the\ArrayAccess
interface) isset($subject[$pathSegment])
is calledObjectStorage::offsetExists
is called with"0"
as argument- The call to
spl_object_hash("0")
causes the warning
I am not sure who is at fault here but I can say the following:
- Accessing a non-existing property in Fluid should never trigger an error
- Implementing the
\ArrayAccess
interface means a promise to be capable of handling the only two natively supported index typesstring
andinteger
Attached is a patch which performs a simple check via is_object
.
Files
Updated by Mathias Brodala almost 10 years ago
Updated by Gerrit Code Review almost 10 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33615
Updated by Gerrit Code Review over 9 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33615
Updated by Gerrit Code Review over 9 years ago
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/34433
Updated by Mathias Brodala over 9 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 279d0ac91f918fd41db4d7187860ef51347aa732.