In PHP is it posible to have an array where a string was previously stored?
echo "valuebefore: ".$_SESSION['REQUEST_TOKEN'][TL_MODE];
$_SESSION['REQUEST_TOKEN'][TL_MODE] = "somestring";
echo "typebefore: ".gettype($_SESSION['REQUEST_TOKEN'][TL_MODE]);
$_SESSION['REQUEST_TOKEN'][TL_MODE] = array();
echo "typeafter: ".gettype($_SESSION['REQUEST_TOKEN'][TL_MODE]);
if (!is_array($_SESSION['REQUEST_TOKEN'][TL_MODE]))
{
echo "is not an array";
}
echo "valueafter: ".$_SESSION['REQUEST_TOKEN'][TL_MODE];
and the output is:
valuebefore: A
typebefore: string
typeafter: string << the type didnt change to array!
is not an array
valueafter: A << the value was not updated!
Why can’t it just hold the new array?
How come the value has not changed either?
Edit:
Here is the vardump for other variables involved:
echo var_dump(TL_MODE)." <br/>";
echo var_dump($_SESSION['REQUEST_TOKEN'])." <br/>";
echo var_dump($_SESSION['REQUEST_TOKEN'][TL_MODE])." <br/>";
output:
string(2) "FE"
string(32) "A96665c9f1e41d1745bf3a3d75cff33a"
string(1) "A"
@Brent Baisley is right on that $_SESSION[‘REQUEST_TOKEN’] is not an array it’s a string, but the base problem turned out to be a cookie related issue that was corrupting the $_SESSION data.
As soon as I cleared cookies and cache in the web browser all worked fine.