[+BUGFIX] Fluid (Core): Simplify debugging of exceptions thrown during render
authorSebastian Kurfuerst <sebastian@typo3.org>
Sun, 19 Jun 2011 08:16:40 +0000 (10:16 +0200)
committerSebastian Kurfuerst <sebastian@typo3.org>
Mon, 20 Jun 2011 07:40:21 +0000 (09:40 +0200)
If a sub node of the SyntaxTree throws an exception, PHP would issue a
fatal error because __toString() methods must not throw exceptions.

This patch fixes this odd behavior by calling __toString() explicitly.

Related Fluid (FLOW3) change: I824cbf1bfde8c571daf67ea08b87b6d137754a09

Change-Id: Id3454bbac2f212ff9a87f0f71ce43ffd62ffa43c

typo3/sysext/fluid/Classes/Core/Parser/SyntaxTree/AbstractNode.php

index a9eb5a5..17436e5 100644 (file)
@@ -47,16 +47,24 @@ abstract class Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode implements Tx_Fluid_
                        if ($output === NULL) {
                                $output = $subNode->evaluate($renderingContext);
                        } else {
-                               if (is_object($output) && !method_exists($output, '__toString')) {
-                                       throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1248356140);
+                               if (is_object($output)) {
+                                       if (!method_exists($output, '__toString')) {
+                                               throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1248356140);
+                                       }
+                                       $output = $output->__toString();
+                               } else {
+                                       $output = (string)$output;
                                }
-                               $output = (string)$output;
                                $subNodeOutput = $subNode->evaluate($renderingContext);
 
-                               if (is_object($subNodeOutput) && !method_exists($subNodeOutput, '__toString')) {
-                                       throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($subNodeOutput) . '" to string.', 1273753083);
+                               if (is_object($subNodeOutput)) {
+                                       if (!method_exists($subNodeOutput, '__toString')) {
+                                               throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($subNodeOutput) . '" to string.', 1273753083);
+                                       }
+                                       $output .= $subNodeOutput->__toString();
+                               } else {
+                                       $output .= (string)$subNodeOutput;
                                }
-                               $output .= (string)$subNodeOutput;
                        }
                }
                return $output;