开发者

php weird bug where an array is not an array

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 anym开发者_Python百科ore 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 !


The variable $compiled_tags is getting overwritten by something, probably the method call.

Try adding print_r($compiled_tags); between each line and then see where it changes from an empty array to a scalar. I would bet it happens after the method call $this->_compile_tag()


As far as I'm aware, $compiled_tags[] will ALWAYS work. There may be a problem somewhere else in your code. Maybe _compile_tag() uses $compiled_tags as a global?


What's the scope of $compiled_tags?

It looks like the method _compile_tag(...) may be setting it to an integer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜