I’m having some woes with the above stated warning on an array.
I completely understand what the warning is, and what causes it, and I have taken every step I can to prevent it, but alas, none are having any effect.
Steps taken:
I have Checked for the array, declared it if not exists.
if(!$this->theVariables['associated']){
$this->theVariables['associated'] = array();
}
and
$this->theVariables['associated'] = $this->theVariables['associated'] || array();
Neither have any effect.
I have wrapped the foreach in an if that checks the array is not empty (!empty()), that it exists, that it is an array (is_array()), and then even type cast the array in the foreach declaration (foreach((array)$this->theVariables['associated'] as $item)) yet I am still getting this Warning.
As I have no way of switching error reporting off on this specific server, is there no other way of stopping this warning from displaying?
It is driving me nuts.
try:
bacause for example if
$this->theVariables['associated']would be1this array assignment would never be reached:(The same goes for your second test)
As for Ólafur Waages comment, have a look at Lazy evaluation.
For example, if your test looked something like this, you’ll probably get problems:
Output: