Edit report at http://bugs.php.net/bug.php?id=54950&edit=1

 ID:                 54950
 Comment by:         marc-bennewitz at arcor dot de
 Reported by:        marc-bennewitz at arcor dot de
 Summary:            simplexml_load_[string|file]: error_get_last is
                     useless
 Status:             Open
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   Linux
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

OK 'libxml_use_internal_errors' can also be used

but the last reported error is unhelpful anyhow


Previous Comments:
------------------------------------------------------------------------
[2011-05-29 18:07:26] marc-bennewitz at arcor dot de

Description:
------------
On loading an invalid xml catched errors using error_get_last aren't
helpful because the message is nearly empty "simplexml_load_string():   
     ^"



It looks like there are more errors reported and the last error is the
most unhelpful error but this is the only good catchable error (see
example).



A workaround only exists using an own error handler but it's nasty :(

Test script:
---------------
$xml = <<<XML

<?xml version="1.0"?>

<config>

    <a>test</a>

</other>

XML;



echo 'LOAD INVALID XML STRING' . PHP_EOL;

$simpleXML = simplexml_load_string($xml);



echo 'DETECTED ERROR:' . PHP_EOL;

if ($simpleXML === false) {

    $err = error_get_last();

    var_dump($err);

}

Expected result:
----------------
LOAD INVALID XML STRING

PHP Warning:  simplexml_load_string(): Entity: line 4: parser error :
Opening and ending tag mismatch: config line 2 and other in
/tmp/bug_simpleXmlLoad.php on line 11



Warning: simplexml_load_string(): Entity: line 4: parser error : Opening
and ending tag mismatch: config line 2 and other in
/tmp/bug_simpleXmlLoad.php on line 11

DETECTED ERROR:

array(4) {

  ["type"]=>

  int(2)

  ["message"]=>

  string(34) "simplexml_load_string(): Entity: line 4: parser error :
Opening and ending tag mismatch: config line 2 and other"

  ["file"]=>

  string(26) "/tmp/bug_simpleXmlLoad.php"

  ["line"]=>

  int(11)

}

Actual result:
--------------
LOAD INVALID XML STRING

PHP Warning:  simplexml_load_string(): Entity: line 4: parser error :
Opening and ending tag mismatch: config line 2 and other in
/tmp/bug_simpleXmlLoad.php on line 11



Warning: simplexml_load_string(): Entity: line 4: parser error : Opening
and ending tag mismatch: config line 2 and other in
/tmp/bug_simpleXmlLoad.php on line 11

PHP Warning:  simplexml_load_string(): </other> in
/tmp/bug_simpleXmlLoad.php on line 11



Warning: simplexml_load_string(): </other> in /tmp/bug_simpleXmlLoad.php
on line 11

PHP Warning:  simplexml_load_string():         ^ in
/tmp/bug_simpleXmlLoad.php on line 11



Warning: simplexml_load_string():         ^ in
/tmp/bug_simpleXmlLoad.php on line 11

DETECTED ERROR:

array(4) {

  ["type"]=>

  int(2)

  ["message"]=>

  string(34) "simplexml_load_string():         ^"

  ["file"]=>

  string(26) "/tmp/bug_simpleXmlLoad.php"

  ["line"]=>

  int(11)

}


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54950&edit=1

Reply via email to