SimpleXML Element and Session Variables
Monday, August 3rd, 2009As you may have guessed, I am writing this because there is an issue with using SimpleXML and Session variables in conjunction with each other. Sessions apparently do not know how to handle object resource values that the SimpleXML engine generates. If you attempt to assign a Session variable to a SimpleXML object value you will get an error similar to this:
Warning: session_start() [function.session-start]: Node no longer exists
Here is an example of assigning the Session variable the “wrong way” (from Authorize.net CIM API):
$_SESSION['profileid'] = $this->results->customerProfileId;
And here is the correct way to assign the Session variable:
$_SESSION['profileid'] = (int)$this->results->customerProfileId;
If the expected data type of the object value is to be a string use (string)
That’s about it for now . . .
