I want to update an old PHP code, where there is used a lot of sizeof()
function for empty arrays like:
<?php
$a=array();
#...
if(sizeof($a['somthing_set_later'])>0){
#...
}
$a['somthing_set_later']="something";
which throws:
sizeof(): Parameter must be an array or an object that implements Countable
To fix this I could initially fill those arrays with null
or check for is_countable()
first, but I would like to find_and_replace the code over the whole project, which would be easy, if there was another function that doesn't complain.
Is there an alternative function, that wouldn't throw a warning on this code?
Update: optimal would be a built-in function for speed.