I am having this problem When using callback functions
Class My_Class {
public function my_function() {
$pad = function($value) {
return str_pad($value, 2, '0', STR_PAD_LEFT);
};
function pad_function($value) {
return str_pad($value, 2, '0', STR_PAD_LEFT);
}
array_map($pad, range(0,100)); //This fails with an exception "Invalid opcode 153/1/8."
array_map("pad_function", range(0,100)); //This works ok
}
}
I am using PHP version 5.3.3-7.
Any ideas of why this is happening?
Thanks in advance!
Typos apart,
$pad
is never defined.Then
array_map
won't call your$my_pad_function
lambda function, because you passed themy_pad_function
string as first parameter, telling PHP to look for a function namedmy_pad_function
: that's different from calling a lambda stored in$my_pad_function
.Anyway I advice you not to call everything "my_function", "myPrettyFunction", "myPointlessNameVar": give meaningful names even in playground code, your goal will be clearer.
One last thing:
Finally the problem was with eaccelerator.
Version 1.0-dev of eaccelerator carashes when executing the code. Version 0.9.6.1 of eaccelerator does not crash with the code.