Last active
January 29, 2016 01:32
-
-
Save kurozumi/312de37679852729c32f to your computer and use it in GitHub Desktop.
【PHP】不変オブジェクト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme; | |
class Immutable | |
{ | |
protected $some = "some"; | |
public function getSome() | |
{ | |
return $this->some; | |
} | |
public function withSome($some) | |
{ | |
$clone = clone $this; | |
$clone->some = $some; | |
return $clone; | |
} | |
public function __set($name, $value) | |
{ | |
throw new \InvalidArgumentException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment