Emanuil Rusev
Emanuil Rusev

Reputation: 35285

Anonymous functions pre PHP 5.3.0

Is there an alternative to anonymous functions in versions of PHP previous to 5.3.0?

Upvotes: 3

Views: 546

Answers (3)

tamasd
tamasd

Reputation: 5923

There are two choices.

First is to create a function, inside a function. Unfortunately, it will pollute the global namespace.

The second choice is to use create_function.

Upvotes: 2

BoltClock
BoltClock

Reputation: 724552

Yes, create_function()

Upvotes: 2

Jani Hartikainen
Jani Hartikainen

Reputation: 43273

There is create_function but it generally isn't recommended. If you're using OOP, you'd be better off defining a one-off private member to use with a callback instead.

Upvotes: 5

Related Questions