theITvideos Posted October 26, 2010 Share Posted October 26, 2010 Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! Quote Link to comment Share on other sites More sharing options...
anups Posted October 26, 2010 Share Posted October 26, 2010 There is no way to store simple xmlobject in session. you can convert that object to array serialize it and save it in session and every time you want to do the calculation unserialize it and perform the operation on array. to convert simple XML object to array there is good function on PHP.NET http://www.php.net/manual/en/book.simplexml.php#98077 NOTE :- SimpleXMLElement wraps a libxml resource type. Resources cannot be serialized. On the next invocation, the resource representing the libxml Node object doesn't exist, so unserialization fails. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.