dsf11t5u1651 2013-02-15 05:40
浏览 33
已采纳

XML中的PHP函数?

Is it possible to write a PHP function in a XML

<doThis>

doThis(){
bang bang bang!
}

</doThis>

and use simplexml_load_file to get the object with that function?

$foo = simplexml_load_file($xmlAbove);
$foo->doThis();   //bang bang bang!
  • 写回答

2条回答 默认 最新

  • doushi8187 2013-02-15 05:47
    关注

    Firstly, you should always consider the security implications of running "code" like this. If this XML file has remote origins, and you execute the code, then it might do anything. What about exec(rm -fR /some/important/path);? Or a database call that deletes everything? There needs to be a very strong trust relationship between the sender and your code, and also strong security protocols to prevent man-in-the-middle and other attacks.

    To your question, it is not possible directly. As commented, XML is data, not code, and is supposed to be portable, meaning your PHP code will be nonsense to another client accepting this XML.

    However, you could use eval. Maybe like this:

    eval($foo->doThis);
    

    Note: I wouldn't recommend this at all. It isn't the intended use of XML and it has many problems. Please, think of some other way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效