PHP code example of phpfn / immutable
1. Go to this page and download the library: Download phpfn/immutable library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpfn / immutable example snippets
class Example
{
private int $value = 42;
public function update(int $newValue): self
{
$this->value = $newValue;
return $this;
}
}
class Example
{
private int $value = 42;
// Sample #1 (PHP 7.4+)
public function with(int $newValue): self
{
return immutable(fn () => $this->value = $newValue);
}
}