Warning count(): Parameter must be an array or an object that implements – Fixed

3.06K views
no comments
17 Mar 2019 1:39 am

New version 7.2 of PHP is little bit restrict for calling functions and passing parameters, now count() function will only count variable and it will thrown an error when parameter is not array.

Here is quick fix I have create my own function for counting array or object and it that function will return 0 if parameter contains string or anything else.

Alternate count function for php 7.2+

function fixed_count($array_obj){
	if(!is_array($array_obj)){
		$array_obj = (array) $array_obj;
	}
	try{
		return count($array_obj);
	} catch(Exception $exc){ //for laravel add back slash \ before Exception eg: (\Exception)
		return 0;
	}
}

Now just you have add that function your project library or project helper and find count( function and replace with fixed_count(

Enjoy!

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>