PHP RFC on immutability

I recently started exploring the realm of functional programming in PHP and came across the PHP RFC on immutable classes and properties. Simply put, the RFC, short for Request For Comments, which is a means for developers to propose language changes, zeroes in on extending immutability beyond the reach of constant variables which are, only suitable for scalar values.

Immutability, the inability of language constructs to change their values once assigned, is vital to preserving state in functional applications. This concept is central to the paradigm of functional programming as it makes code a lot easier to evaluate and debug.

The current PHP structure does not accommodate features present in functional languages, Haskell and Scala such as data sharing, and lazy evaluation: the workaround for this includes value objects and garbage collection, viable approaches though not as potent as the aforementioned functional language concepts.

PHP however, does allow those who use it to compose pure functions by keenly spotting side effects and side-causes which result from state changes, use small functions in conjunction with value objects to create referential transparency, and use an array of algorithms to handle collections.

The implication of approval of this proposal would make PHP more robust as well as add more organic, stable support for its functional programming environment. Check out the RFC by following this link:

I write PHP and I know things — kind of.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lochemem Bruno Michael

Lochemem Bruno Michael

I write PHP and I know things — kind of.

More from Medium

Using Enum in Symfony

Node.js vs PHP. Choosing Between Modernity and Tradition

PHP — P44: Class Properties

Php 8.1-New Features | Array is a list? & Array Unpack