note 115649 added to simplexmlelement.construct

From: Date: Mon, 01 Sep 2014 11:39:44 +0000
Subject: note 115649 added to simplexmlelement.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-200354@lists.php.net to get a copy of this message
It's worth noting, that you need to typecast dynamic property names to string in order to retrieve there value, for example: <?php $xml = new SimpleXMLElement('records.xml', 0, true); // This will work as expected because its a hard coded property value foreach($xml as $record){ echo $record->id; // Will output the ID fine } // Dynamic properties require typecasting to string $xml_field = 'id'; foreach($xml as $record){ // This will dump a SimpleXMLElement object var_dump($record->$xml_field); // This will output the value as expected echo (string)$record->$xml_field; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 46.60.252.113 ---- Manual Page -- http://php.net/manual/en/simplexmlelement.construct.php Edit -- https://master.php.net/note/edit/115649 Del: integrated -- https://master.php.net/note/delete/115649/integrated Del: useless -- https://master.php.net/note/delete/115649/useless Del: bad code -- https://master.php.net/note/delete/115649/bad+code Del: spam -- https://master.php.net/note/delete/115649/spam Del: non-english -- https://master.php.net/note/delete/115649/non-english Del: in docs -- https://master.php.net/note/delete/115649/in+docs Del: other reasons-- https://master.php.net/note/delete/115649 Reject -- https://master.php.net/note/reject/115649 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200354) next »