Rationale behind SimpleXMLElement's handling of text values in addChild and addAttribute

前端 未结 6 956
别那么骄傲
别那么骄傲 2020-12-01 09:16

Isn\'t that an inconsistent behavior? (PHP 5.2.6)

\');

$a->addAttribute(\'b\', \'One & Two\');
//$a-&         


        
6条回答
  •  心在旅途
    2020-12-01 09:40

    Alan Storm had a nice description of the issue, however there's an easy solution to the paradox he describes. The addChild() method could have an optional boolean parameter that determines whether to automatically escape characters. So, I'm still convinced that it's simply a (very) poor design choice.

    The confusion is compounded by the fact the the documentation for the addChild() method makes no reference whatsoever so the issue (although is is in the discussion). Furthermore, the method escapes some characters (namely the less than and greater than signs). This will mislead developers using the method to believe that it escapes characters in general.

提交回复
热议问题