Bug #62553

Exception when accessing empty ObjectStorage property via numeric index

Added by Mathias Brodala about 5 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Must have
Category:
Extbase
Target version:
Start date:
2014-10-30
Due date:
% Done:

100%

TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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:

  1. Fluid parser calls \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::getPropertyPath
  2. The property "0" is not found via \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyInternal
  3. The array check yields TRUE (ObjectStorage implements the \ArrayAccess interface)
  4. isset($subject[$pathSegment]) is called
  5. ObjectStorage::offsetExists is called with "0" as argument
  6. 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 types string and integer

Attached is a patch which performs a simple check via is_object.

objectstorage-offsetexists-check-object.patch View - Fix isset() call on ObjectStorage with numeric index (612 Bytes) Mathias Brodala, 2014-10-30 11:26

objectstorage-offsetexists-check-object.patch View - Fix + Unit tests (1.66 KB) Mathias Brodala, 2014-10-30 11:36

Associated revisions

Revision 279d0ac9 (diff)
Added by Mathias Brodala almost 5 years ago

[BUGFIX] Fix access to empty ObjectStorage with numeric key

This prevents a warning error triggered by spl_object_hash being called
with an integer/string and can be caused by Fluid like this:

{object.relations.0}

Resolves: #62553
Releases: master, 6.2
Change-Id: Ie7d2a249e17f719142482781c2a96d093ff5f94c
Reviewed-on: http://review.typo3.org/33615
Reviewed-by: Mathias Schreiber <>
Tested-by: Mathias Schreiber <>
Reviewed-by: Markus Klein <>
Tested-by: Markus Klein <>

Revision 8d9ed038 (diff)
Added by Mathias Brodala almost 5 years ago

[BUGFIX] Fix access to empty ObjectStorage with numeric key

This prevents a warning error triggered by spl_object_hash being called
with an integer/string and can be caused by Fluid like this:

{object.relations.0}

Resolves: #62553
Releases: master, 6.2
Change-Id: Ie7d2a249e17f719142482781c2a96d093ff5f94c
Reviewed-on: http://review.typo3.org/34433
Reviewed-by: Markus Klein <>
Tested-by: Markus Klein <>

History

#2 Updated by Gerrit Code Review about 5 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

#3 Updated by Gerrit Code Review almost 5 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

#4 Updated by Gerrit Code Review almost 5 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

#5 Updated by Mathias Brodala almost 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#6 Updated by Benni Mack about 1 year ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF