note 54055 deleted from ref.simplexml by derick
| From: | derick@php.net | Date: | Thu, 13 Oct 2005 13:43:54 +0000 |
| Subject: | note 54055 deleted from ref.simplexml by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96949@lists.php.net to get a copy of this message | ||
Note Submitter: tom at lemuria dot org
----
SimpleXML does not appear to mix very well with sessions. Casting the values explicitly solves this
problem.
This does NOT work and will yield errors if Foo is used in a session (i.e. you do a
$_SESSION['foo']=new Foo();):
<?php
class Foo {
public bar;
function __construct() {
$xml = simplexml_load_file('bar.xml');
$this->bar=$xml->something->bar;
}
}
?>
However, by adding an explicit cast, things work just fine:
<?php
class Foo {
public bar;
function __construct() {
$xml = simplexml_load_file('bar.xml');
$this->bar=(string)$xml->something->bar;
}
}
?>
The above is true for PHP 5.0.4 - no guarantees for other versions.