【发布时间】:2019-08-03 09:11:16
【问题描述】:
这是我在文件中的代码的 sn-p public_html/wp-content/themes/arabv3/CustomMetaBox/CMB2.php,从第 565 行开始
// if it's an array of one, extract it
elseif ( is_array( $this->prop( 'object_types' ) ) && count( $this->prop( 'object_types' ) === 1 ) ) {
$cpts = $this->prop( 'object_types' );
$type = is_string( end( $cpts ) )
? end( $cpts )
: false;
}
当我运行代码时,我收到以下错误:
PHP 警告:count():参数必须是数组或实现了 Countable 的对象
【问题讨论】:
-
显然
count()作用的属性不是数组也不是可数的,参考$this->prop('object_types')。它作用于布尔值,因为count()具有比较功能 -
你有一个错字。将
count($this->prop('object_types') === 1 )更改为count($this->prop('object_types')) === 1。