note 86861 deleted from function.simplexml-element-construct by danbrown

From: Date: Wed, 16 Sep 2009 15:45:38 +0000
Subject: note 86861 deleted from function.simplexml-element-construct by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160662@lists.php.net to get a copy of this message
Note Submitter: jmshinn at gmail dot com ---- Note to tudor: You can't override the constructor, but you can get around that with a simple static method: <?php class simpleXmlExtender extends SimpleXMLElement { public static function _new($xml=NULL, $ns=NULL, $prefix=TRUE) { // allows you to set certain option parameters to new default values, // or automatically decide whether input data is a file or not // optionally, you can save the object in an intermediate variable // and peform other actions on/with it before returning it return new simpleXmlExtender($xml, LIBXML_NOCDATA, file_exists($xml), $ns, $prefix); } } $simpleXML = simpleXmlExtender::_new($xmldata); ?> ... it's a bit of a hack, but it works.

« previous php.notes (#160662) next »