Warning: count(): Parameter must be an array or an object that implements Countable in~

PHPを7.2にしたら、今まで問題なかったプラグインに対して、Warning: count(): Parameter must be an array or an object that implements Countable in~ などというエラーが…

count関数が変数の中を数えられないって???

こんなことこれまでなかったのに
いきなり数えるの拒否?

どうやら、PHP7.2で count()関数の仕様が変更になったようです
どうやらcountで数えたい変数の中身がNULLだとエラーになるようになったようです

なので、countしたい変数がNULLじゃなかったら、countしてよ♪
と、if文で追記してエラー回避

 

例)$serrchが空じゃなかったらcountしてよね!

			if ( count( $search ) === 1 ) {
				$settings = $this->create_ghost_settings( $settings );
			} else {
				$settings[ $this->ID ] = $this->create_ghost_settings( $settings[ $this->ID ] );
			}
		

		if ( ! empty( $search ) ) {

			if ( count( $search ) === 1 ) {
				$settings = $this->create_ghost_settings( $settings );
			} else {
				$settings[ $this->ID ] = $this->create_ghost_settings( $settings[ $this->ID ] );
			}
		
		} else {
        	$search = 0;
    	}

 

 

最近EC-CUBE3(もうEC-CUBE4が出たけれど)で、記述が間違っていないはずなのにどうしてもエラーが出ることが
原因はタブだった…
くせでブランクを半角ではなくタブ使っていたのが原因
タブはダメって知っていたのに実践できていなかった
無駄な時間を費やしてしまいました

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA