php weird bug where an array is not an array !

Posted by iko on Stack Overflow See other posts from Stack Overflow or by iko
Published on 2010-03-19T13:42:26Z Indexed on 2010/03/19 13:51 UTC
Read the original article Hit count: 163

Filed under:
|

I've been going mad trying to figure out why an array would not be an array in php.

For a reason I can't understand I have a bug in a smarty class. The code is this :

$compiled_tags = array();
for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) {
   $this->_current_line_no += substr_count($text_blocks[$i], "\n");

   // I tried array push instead to see
   // bug is here
   array_push($compiled_tags,$this->_compile_tag($template_tags[$i]));
   //$compiled_tags[] = $this->_compile_tag($template_tags[$i]);

   $this->_current_line_no += substr_count($template_tags[$i], "\n");

}

the error message is

Warning: array_push() expects parameter 1 to be array, integer given in ....

OR before with []

Warning: Cannot use a scalar value as an array in ....

I trying a var_debug on $compiled_tags and as soon I enter the for loop is not an array anymore but an integer. I tried renaming the variable, but same problem.

I'm sure is something simple that I missed but I can't figure it out. Any help is (as always) welcomed !

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays