By John Koster
value($value)
The value function will return the default value of the supplied $value. Although this sounds redundant, if the supplied $value is an instance of the Closure class, the function will be executed and the value will be returned. If the $value is not an instance of Closure, the value is simply returned.
Using value with an instance of Closure:
1<?php
2
3$value = value(function()
4{
5 return 42;
6});
In the above example, $value would contain the integer 42, because it was returned from the function.
The following example does not use an instance of Closure:
1<?php
2
3$value = value(42);
Again, $value would contain the integer 42.
∎