PHPStorm和魔术方法 [英] PHPStorm and magic methods
问题描述
我正在使用PHPStorm,并编写了一个利用SimpleXML类的类.一切都很好,除非遍历XML字符串时,我会收到未定义的属性"警告.
I am using PHPStorm and have written a class that utilises the SimpleXML class. Everything is fine, except when I traverse an XML string I will get "Undefined Property" warnings.
$xml = simplexml_load_string($string); //Returns SimpleXML Element
echo $xml->childElement; //PHPStorm reports "Undefined Property
我相信这是因为在PHPStorm中没有正确定义魔术属性.有人知道周围有一些不错的工作吗?这让我很烦,因为我讨厌拥有漂亮的干净代码(和IDE),并且在类上出现警告真是太糟糕了!
I believe this is because the magic properties are not properly defined in PHPStorm. Is anyone aware of a nice little work around? It annoys me because I am pedantic about having nice clean code (and IDE) and having warnings come up on a class is just awful!
推荐答案
我认为我已经解决了.如果将大括号内的节点封装为字符串,PHPStorm将忽略它们.
I think I've solved it. If I encapsulate the nodes inside curly braces as strings, PHPStorm will ignore these.
echo $xml->{'Parent'}->{'ChildElement'};
例如,如果遇到带连字符的XML标签,则具有保持一致的优点. $xml->{'Parent-Node'}
This has the advantage of being consistent if you encounter an XML tag with a hyphen, for instance. $xml->{'Parent-Node'}
这篇关于PHPStorm和魔术方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!