title: Cannot convert object to string. Returning a function
body: <p>I need to return the response of a function and I get an error</p>
  
  <pre><code>function excel() {
  
      // If I don't add return here, then calling excel() will always be empty.
      // However when calling it I get the error ErrorException
  
      return Excel::load($filePath, function($reader) {
          $results = $reader-&gt;get();
          return $results; // there's an array here
      });
  }
  
  function test() {
    return excel();
  }
  
  return test(); //Empty when it should have an array.
  
  message: "Object of class Maatwebsite\Excel\Readers\LaravelExcelReader could not be converted to string"
  type: "ErrorException"
  </code></pre>
  
  <p>How can I properly achieve what I want? (which at the end is to return $results).</p>
  
  <p>Edit:
  The error is thrown from a file being used in Laravel, which is:</p>
  
  <p>Line 406 
  <code>file: "/App/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php"</code></p>
  
  <p>And the code under the hood there is</p>
  
  <pre><code>public function setContent($content)
  {
      if (null !== $content &amp;&amp; !is_string($content) &amp;&amp; !is_numeric($content) &amp;&amp; !is_callable(array($content, '__toString'))) {
          throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
      }
  
      $this-&gt;content = (string) $content;
  
      return $this;
  }
  </code></pre>
  
  <p>No idea why it goes through that code, need some suggestions.</p>