PHP Referential Transparency

In functional programs, variables once defined do not change their value throughout the program. Functional programs do not have assignment statements. If we have to store some value, we define new variables instead. This eliminates any chances of side effects because any variable can be replaced with its actual value at any point of execution. State of any variable is constant at any instant.


$value = 12;
$value = $value + 1 // this changes the value assigned to the variable $value.
          // The expression is not referentially transparent. 

$new_value  = $value + 1 // assigns a value to the variable $new_value.
          // The expression is referentially transparent. 

Referentially transparent functions are pure functions with immutable data structures.