I have inherited some php code, but I am not a real php programmer.
I have just chased down a bug, and I'd like some advice on it.
The code is full of snippets like:
$paramNum = ControlCentre::getElementIds(ControlCentre::PARAMETER, $bdb, 1, $filterType, $filterId);
$numberOfDpText = $paramNum ? " - (".count($paramNum)." %datapoints)" : "";
Now getElementIds can return a NULL for failure, if the underlying sql reports one ( yes I know that's rubbish too ).
It is defined as returning an empty array if there are no elements to report on, but it turns out that it returns a NULL for that situation too.
I will eventually make it do what it says on the can, but there may/will be cascade effects on code like the above.
So -- it is clear that the code does if() on a variable which may hold an array, or may be NULL.
If this were C, then that would be a common, if mucky, method to ask
if ( NULL == $paramNum )
but this ISN'T C.
So - do the panel agree that the code snippet above is just basically rubbish programming, or is there something subtle in PHP that I don't grok which makes it sensible and well-defined.