1

I have a class that uses 5.3 feature anonymous function (https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php), but there is a problem, on the server I can not upgrade to 5.3. Is there any simple workaround to get rid of anonymous functions or do I need to rewrite whole class?

4
  • 1
    Hopefully you'll find a workaround in this case, but nevertheless it is essential to determine dependencies/requirements of external libraries before committing to using them :-) Commented Mar 4, 2012 at 13:52
  • Yes, didn't knew that server can't handle it. Rewrote the code with core wordpress. Commented Mar 10, 2012 at 8:39
  • I don't understand, what's the problem with just naming the function and calling it? Commented Jul 4, 2012 at 20:48
  • @BenjaminGruenbaum: most of the anonymous functions in that linked file are closures, so that won't work Commented Mar 9, 2013 at 8:28

2 Answers 2

2

You have two options:

  • Change the hosting with PHP version supporting anonymous functions
  • Re-write your code so it works with version of PHP you have
Sign up to request clarification or add additional context in comments.

Comments

0

A workaround for pre PHP 5.3 is to use create_function().

It is ugly as hell and akin to eval(), but it's closest to functionality without defining another function and passing a pointer to it.

1 Comment

With such a big anonymous function (github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/…) it will be hard to use create_function, enclosing all the PHP code in a string... You should create your own function and passing its name to admin_init.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.