Browse Source

[HttpKernel] Making the "no response returned from controller" more explanatory when it's possible that the user forgot a return statement in his/her controller

Also made "null" show up as null in the exception message, instead of as a blank string (slightly more expressive).
Ryan Weaver 14 years ago
parent
commit
80c102761c
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/Symfony/Component/HttpKernel/HttpKernel.php

+ 11 - 1
src/Symfony/Component/HttpKernel/HttpKernel.php

@@ -120,7 +120,13 @@ class HttpKernel implements HttpKernelInterface
             }
 
             if (!$response instanceof Response) {
-                throw new \LogicException(sprintf('The controller must return a response (%s given).', $this->varToString($response)));
+                $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
+
+                // the user may have forgotten to return something
+                if (null === $response) {
+                    $msg .= ' Did you forget to add a return statement somewhere in your controller?';
+                }
+                throw new \LogicException($msg);
             }
         }
 
@@ -187,6 +193,10 @@ class HttpKernel implements HttpKernelInterface
             return '[resource]';
         }
 
+        if (null === $var) {
+            return 'null';
+        }
+
         return str_replace("\n", '', var_export((string) $var, true));
     }
 }