DEV Community

Discussion on: What are your thoughts on functional programming? In PHP?

Collapse
 
d_a_n_d_r_e_i profile image
Andrei • Edited

I'm fascinated by FP and I maintain several PHP codebases. I'd love PHP to be more functional than it is.

What PHP has:

  • First class functions.
  • Arrow functions (as of 7.4).
  • Built in map / filter / reduce.

What PHP lacks:

  • Generics (not needed, but useful).
  • Function types (like TypeScript has, very useful for refactoring / detecting type errors).
  • A proper include mechanism (the autoloading PSRs for mapping namespaces to filesystem paths in order to require / include the right file all presuppose you're going to do OOP).