Quantcast
Channel: PHPDeveloper.org
Viewing all articles
Browse latest Browse all 15

Rob Allen: Throw an exception when simplexml_load_string fails

0
0

In a quick post to his site Rob Allen shares a class that he's created to handle and throw an exception any time that the load from a SimpleXML parsing fails.

I keep having to look up how to stop the warning that are emitted when simplexml_load_string & simplexml_load_file fail, so this time I've written the world's simplest little class to take care of it for me from now on.

His "Xml" class wraps around the SimpleXML functionality and checks to see if the resulting object is false. If it is, it uses some internal error handling to fetch the error message result and throws it as a "RuntimeException". This error string comes from a "getXMLErrorString" function that uses the libxml_get_errors function to get the resulting error list.

Link: http://akrabat.com/php/throw-an-exception-when-simplexml_load_string-fails/

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images