Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active January 29, 2016 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/312de37679852729c32f to your computer and use it in GitHub Desktop.
Save kurozumi/312de37679852729c32f to your computer and use it in GitHub Desktop.
【PHP】不変オブジェクト
<?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