[BUGFIX] Show properties of stdClass object in <f:debug> 08/32108/5
authorChristian Weiske <christian.weiske@netresearch.de>
Tue, 12 Aug 2014 12:13:20 +0000 (14:13 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 13 Aug 2014 18:10:06 +0000 (20:10 +0200)
Using fluid's <f:debug> to get dumps of json_decode()d objects
does not work currently. The DebuggerUtility shows only properties
obtainable via ReflectionClass, which does not work for stdClass objects.

The patch introduces special handling of stdClass objects, using the
properties that actually exist in the object.

Change-Id: I3845178f6defdbceae4b867f45e5080f23443766
Fixes: #60912
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/32108
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/extbase/Classes/Utility/DebuggerUtility.php
typo3/sysext/extbase/Tests/Unit/Utility/DebuggerUtilityTest.php

index 8c4e07d..0801b47 100644 (file)
@@ -311,8 +311,13 @@ class DebuggerUtility {
                        if (!$plainText) {
                                $dump .= '<a name="' . spl_object_hash($object) . '" id="' . spl_object_hash($object) . '"></a>';
                        }
-                       $classReflection = new \ReflectionClass(get_class($object));
-                       $properties = $classReflection->getProperties();
+                       if (get_class($object) === 'stdClass') {
+                               $objReflection = new \ReflectionObject($object);
+                               $properties = $objReflection->getProperties();
+                       } else {
+                               $classReflection = new \ReflectionClass(get_class($object));
+                               $properties = $classReflection->getProperties();
+                       }
                        foreach ($properties as $property) {
                                if (self::isBlacklisted($property)) {
                                        continue;
index 9208345..4765fd6 100644 (file)
@@ -62,4 +62,14 @@ class DebuggerUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $arguments->expects($this->never())->method('rewind');
                $this->debugger->var_dump($arguments, NULL, 8, TRUE, FALSE, TRUE);
        }
+
+       /**
+        * @test
+        */
+       public function varDumpShowsPropertiesOfStdClassObjects() {
+               $testObject = new \stdClass();
+               $testObject->foo = 'bar';
+               $result = $this->debugger->var_dump($testObject, NULL, 8, TRUE, FALSE, TRUE);
+               $this->assertRegExp('/foo.*bar/', $result);
+       }
 }