PHP code example of lisachenko / immutable-object

1. Go to this page and download the library: Download lisachenko/immutable-object 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/ */

    

lisachenko / immutable-object example snippets


use Immutable\ImmutableHandler;
use ZEngine\Core;



declare(strict_types=1);

use Immutable\ImmutableInterface;
use Immutable\ImmutableHandler;
use ZEngine\Core;

c $value;

    public function __construct($value)
    {
        $this->value = $value;
    }
}

$object = new MyImmutableObject(100);
echo $object->value;  // OK, 100
$object->value = 200; // FAIL: LogicException: Immutable object could be modified only in constructor or static methods