Description:
A call of type addAttribute ("attrname", ") leads to" PHP warning: SimpleXMLElement :: addAttribute (): The name and value of the attribute are required. "In addition to the warning, the attribute is discarded.
Play code:
<?php
$xml = new SimpleXmlElement("<img></img>");
$xml->addAttribute("src", "foo");
$xml->addAttribute("alt", "");
echo $xml->asXML()."\n";
?>
Expected Result:
<?xml version="1.0"?>
<img src="foo" alt=""/>
Actual result:
PHP Warning: SimpleXMLElement::addAttribute(): Attribute name and value are required in [...]/test.php on line 4
<?xml version="1.0"?>
<img src="foo"/>
this problem exists in PHP 5.2.1, but in PHP5.3.5 it works as I expect, but I cannot change my php version (for some reason). Is there any way to solve this?
source
share