I’m having a really weird bug with cookies in PHP and I need external view on this case because I can’t figure out what’s going on.
So basically here’s my code :
// Code below does NOT work
$incidents_infos = [];
foreach ($incidents as $incident) {
$incidents_infos[$incident->number]['urgency'] = $incident->urgency;
$incidents_infos[$incident->number]['service_name'] = $this->get_service_name_from_assignment_group($incident->assignment_group);
$incidents_infos[$incident->number]['to_notify'] = $incident->to_notify;
}
setcookie('queried_incidents', json_encode($incidents_infos));
Now the issue that I have and that’s really weird is that the cookie “queried_incidents” is actually set ONLY when the incidents inside $incidents_infos have at most 2 attributes (works with any of the 3 listed).
But when the incidents have the 3 attributes above all together : urgency, service_name, to_notify => although setcookie function DOES return TRUE, the cookie is not actually set in the browser in the end.
// Code below DOES work
$incidents_infos = [];
foreach ($incidents as $incident) {
$incidents_infos[$incident->number]['urgency'] = $incident->urgency;
//$incidents_infos[$incident->number]['service_name'] = $this->get_service_name_from_assignment_group($incident->assignment_group);
$incidents_infos[$incident->number]['to_notify'] = $incident->to_notify;
}
setcookie('queried_incidents', json_encode($incidents_infos));
Apparently is does not have anything to do with the nature of the values of these attributes because I tried any values. After multiple tests, it appears that the cookie is set when the incidents only have 1 or 2 attributes, and does not work with 3 attributes (but setcookie returns true anyway).
I really have NO idea what’s going on, does anyone have an idea ?
Thanks