首页 > 解决方案 > 致命错误:未捕获的错误:调用 /home/acc/public_html/jobs.php 中布尔值的成员函数属性()

问题描述

我的网站出现间歇性问题

https://americascareercenters.us/jobs.php?q=92630

有时页面加载正常。其他时候我只得到一个有错误的空白页。

致命错误:未捕获错误:在 /home/acc/public_html/jobs.php:95 中的布尔值上调用成员函数属性()堆栈跟踪:在 /home/acc/public_html/jobs.php 中抛出 #0 {main}第 95 行

这是代码部分

$rCurl_f = curl_init($sUrl_f);
curl_setopt($rCurl_f, CURLOPT_RETURNTRANSFER, TRUE);
$sXml_f = curl_exec($rCurl_f);
curl_close($rCurl_f);
$oXml_f = simplexml_load_string($sXml_f);

$results_atributes_f = $oXml_f->attributes();
$total_f = $results_atributes_f['total'];

标签: phpxml

解决方案


$oXml_f是的,在尝试使用其方法之前,您需要检查是否为假:

if ( ! empty( $oXml_f ) ) {
    $results_atributes_f = $oXml_f->attributes();
    $total_f = $results_atributes_f['total'];
} else {
    //Whatever you want to do if it fails
    //Maybe $total_f = 0;
}

推荐阅读