Functional Programming in PHP

Modern PHP is mostly written Object Oriented. Other than the fact that there is inertia towards the Object Oriented in the PHP community, is there anything about the language itself that would make it a poor idea to use functional programming?


There’s nothing missing from the language itself that would prevent you from doing functional programming. The only thing missing from the runtime is tail call optimization, and you can actually do quite a bit of FP before hitting that limitation.

What’s really going to hurt you if you try to do FP in PHP is lack of library support for it. You need a fundamentally different collections library, and functional programmers use more semantically precise library functions in many cases where imperative programmers use built-in loops and other language features. Without that library support, you can technically do FP, but you’re going to be reinventing the wheel a lot, and likely not doing what other programmers would recognize as idiomatic FP.


Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *