note 54055 added to ref.simplexml

From: Date: Wed, 22 Jun 2005 11:54:37 +0000
Subject: note 54055 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-90789@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54055 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54055&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54055&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90789) next »