我有一个cron脚本,它将一个curl响应读入SimpleXMLElement。
最近经过一个多月的顺利运行后,我开始收到来自cron的电子邮件,其错误如下:
Warning: SimpleXMLElement::__construct(): Entity: line 4: parser error : XML declaration allowed only at the start of the document in ...
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in ...
Stack trace:
#0 /home/cronscript.php(220): SimpleXMLElement->__construct('<?xml version="...')
#1 {main}
这与不良反应有关吗?如果没有,为什么它会突然开始抛出这样的错误?
最后,我如何预先声明SimpleXMLElement呢? php.net上的所有示例仅在使用时声明它。我可以先声明它,然后再提供数据吗?这样做的正确方法是什么?