Description
- Laravel Version: 5.4.24
- PHP Version: 7.0
- Database Driver & Version: MySQL 5.7
Description:
I ran into a bug regarding cookies that's directly related to a recent update of the symfony/http-foundation package: 3.2.9 -> 3.3.0. I think I found the pull request that's responsible for this as well.
The problem occurs when putting array values in a Cookie and attaching it to the response headers.
Steps To Reproduce:
code:
<?php
namespace App\Controllers;
class CookieController
{
public function createCookie()
{
$array = array(0 => 1);
$cookie = cookie('array', $array, 0);
return response(['message'], 200)->withCookie($cookie);
}
}
- make sure you update your packages with composer and
"symfony/http-foundation": 3.3.*
is installed; - test the above code using a route to the above controller and action method;
- an exception occurs saying:
[Symfony\Component\Debug\Exception\FatalErrorException]
Method Symfony\Component\HttpFoundation\Cookie::__toString() must not throw
an exception, caught ErrorException: Array to string conversion
The code above is a simple as I can reproduce the code I have in my production application. I've tested the same code using a fixed dependency to "symfony/http-foundation": 3.2.*
and the code runs without a problem.
I don't have enough deep knowledge of symfony to suggest a fix. But maybe another contributor understand what's going on here. I'm using this code since Laravel 4.2 and always worked.
Let me know if I need to elaborate some more!
Thomas,