From 54ce7af6f3fb7f26ab6107e646bef5438196522d Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@googlemail.com>
Date: Thu, 4 Dec 2014 20:21:39 +0100
Subject: [PATCH] refs #5144 better fix for array to string to conversion.

Noticed this hack while I worked on the tracker refactoring. Dispatch
should always return a string. Fixing the problem where it actually occurs.
An even better fix would be not to support serialize=0 for format PHP as
it is meant only for internal requests. If someone wants to access data
serialize=1 should be set.
---
 core/dispatch.php          | 4 +---
 plugins/API/Controller.php | 8 +++++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/core/dispatch.php b/core/dispatch.php
index 7f04a15664..86b810500a 100644
--- a/core/dispatch.php
+++ b/core/dispatch.php
@@ -35,9 +35,7 @@ if (PIWIK_ENABLE_DISPATCH) {
         $controller->init();
         $response = $controller->dispatch();
 
-        if (is_array($response)) {
-            var_export($response);
-        } elseif (!is_null($response)) {
+        if (!is_null($response)) {
             echo $response;
         }
     } catch (Exception $ex) {
diff --git a/plugins/API/Controller.php b/plugins/API/Controller.php
index 18e39d58a2..d11f953704 100644
--- a/plugins/API/Controller.php
+++ b/plugins/API/Controller.php
@@ -30,7 +30,13 @@ class Controller extends \Piwik\Plugin\Controller
         }
 
         $request = new Request('token_auth=' . Common::getRequestVar('token_auth', 'anonymous', 'string'));
-        return $request->process();
+        $response = $request->process();
+
+        if (is_array($response)) {
+            $response = var_export($response, true);
+        }
+
+        return $response;
     }
 
     public function listAllMethods()
-- 
GitLab