0

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!

5
  • Where is $pad defined? Commented Aug 23, 2012 at 2:37
  • there's a blatant syntax error... Commented Aug 23, 2012 at 2:38
  • Fix the syntax error first please. Commented Aug 23, 2012 at 2:38
  • The "invalid opcode" error looks like a bug in PHP. PHP 5.3.3 is rather outdated; try upgrading to 5.3.16 and see if that fixes it. Commented Aug 23, 2012 at 4:13
  • I just fixed the syntax error, i tried to rush it too much. Any ideas? Commented Aug 23, 2012 at 4:41

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Typos apart, $pad is never defined.

Then array_map won't call your $my_pad_function lambda function, because you passed the my_pad_function string as first parameter, telling PHP to look for a function named my_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:

lambdas : PHP = lipstick : pig

1 Comment

Thanks for the advices, the reason for calling them My_Whatever is because i didn't want to just copy & paste my own code (as it contains more vars and so on), that is also the reason why there were so many errors :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.