Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active Jan 29, 2016
Embed
What would you like to do?
【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