From the course: Functional Programming with PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Immutability in functional programming

Immutability in functional programming - PHP Tutorial

From the course: Functional Programming with PHP

Start my 1-month free trial

Immutability in functional programming

- [Instructor] The first major concept of functional programming is immutability. And it's a concept that may surprise a lot of people at first. See, most programmers learned early on that you could assign a value to a variable. For example, we can define a variable called x and store the value five in it. And then later on in the program, we can change the value of that variable to some completely different number. And later on, we can change this value again and so on. However, in Functional Programming, this is not allowed. When we say that x is equal to five, we mean that for the rest of the program, x will only ever be five, there's no way we can change it. In short, immutability means that we need to treat most of the values in a program is constants. In PHP 7, we have two main ways of defining constants. The first way is with the const keyword, which defines constants at compile time. And the second is by using…

Contents