Sizeof() warning

I have

if(sizeof($assetArray >= 1)) {

which seems to work, but produces…
Warning : sizeof(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\DCT\2\racks\show_rack.php on line 411



gives me
am i doing it wrong?

It’s not at all clear, nor logical in any way that I can think of, to request the sizeof something called “$assetArray >= 1”. I suspect you want to test if the size of the array is >= 1, and have just put a parenthesis in the wrong place.

Instead of:



Try using count($assetArray) which should produce a numeric of zero or an integer.

The if statement parameter count(…) will convert the zero to false and positive integers to true.

Check the free online PHP manual when in doubt:

See Also

  • is_array() - Finds whether a variable is an array
  • isset() - Determine if a variable is declared and is different than null
  • empty() - Determine whether a variable is empty
  • strlen() - Get string length
  • is_countable() - Verify that the contents of a variable is a countable value


Try adding declare(strict_types=1); as the first statement in the PHP file which will halt the process and produce errors instead of warnings which may be hidden.

1 Like