Zendでcountでwarningがでる

この記事は約2分で読めます。
スポンサーリンク

PHPバージョンが7系になってくると、count関数にnullが入ってくるとエラーがでるようになった。

Warning:  count(): Parameter must be an array or an object that implements Countable in /xxxxxxxxxxxxxxx/Zend/1.12.13/Zend/Db/Table/Abstract.php on line 1307

エラーコードによるとAbstract.phpの1307行目で引っかかっているのでこちらを修正。

$keyValuesCount = count($keyValues);
// Coerce the values to an array.
// Don't simply typecast to array, because the values
// might be Zend_Db_Expr objects.
if (!is_array($keyValues)) {
$keyValues = array($keyValues);
}

一段目の変数の部分をif文の下に移動させればif文でcountする前にnullが消えるので回避ができるようになる

// Coerce the values to an array.
// Don't simply typecast to array, because the values
// might be Zend_Db_Expr objects.
if (!is_array($keyValues)) {
$keyValues = array($keyValues);
}
$keyValuesCount = count($keyValues);

コメント

タイトルとURLをコピーしました