GTS Joe GTS Joe - 8 months ago 60
PHP Question

die Function Not Triggering

In the following code, the die() function should execute since the URL I pass to simplexml_load_file() is bad. simplexml_load_file() returns FALSE, which should trigger die():

$url = '';

$xml = simplexml_load_file($url) or die('Error: Can\'t create the object.');

How come instead I'm getting the following error message?

Warning: simplexml_load_file( failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /var/www/ on line 16

Warning: simplexml_load_file(): I/O warning : failed to load external entity "" in /var/www/ on line 16
Error: Can't create the object.


You can use the @ operator if you want silence the warning, or disable display_errors.

$xml = @simplexml_load_file($url) or die('Error: Can\'t create the object.');

simplexml_load_file returns false with or without the warning, and die is executed anyway.