3 ms·
How do classes, anonymous functions and functions in PHP differ from those in _insert_your_language_of_choice?
by rokhayakebe 16y ago
How do classes, anonymous functions and functions in PHP differ from those in _insert_your_language_of_choice?
- Udo 16y agoI love those features in PHP, especially OO and anonymous functions as a way to organize my code, make it more readable and maintainable. However, I'm not using them strictly in a conceptually pure way. OO was meant to lead to massive inheritance schemes, and PHP is just not a suitable environment for that paradigm. The reason why most PHP devs don't go off on massive Java-like inheritance sprees is PHP's execution model. It's strictly request-based. For every request, PHP code creates an environment to service it, and then everything gets discarded. This is one of the strengths of PHP, actually, it makes PHP apps stateless in many respects. However, this also means that it is unwise to build computationally wasteful structures like extensive OO schemes - at least for performance-conscious production environments. Contrast this to Java or ASP.NET apps, for example, where the cost of initializing massive OO frameworks is offset by the fact that they stay intact across requests. So I believe OO features are very good and important for PHP, as long as developers keep the computational cost in mind. Also, closures are awesome.