<?php
trait Immutable {
public function __set($name, $value) {
throw new Exception('<iframe width="420" height="315" src="https://www.youtube.com/embed/otCpCn0l4Wo?t=14" frameborder="0" allowfullscreen></iframe>');
}
public function __get($name) {
return $this->$name;
}
}
class ImmutableThingy {
use Immutable;
protected $foo = 'bar';
}
$thing = new ImmutableThingy;
var_dump($thing, $thing->foo);
$thing->foo = 'baz';
var_dump($thing, $thing->foo);
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- object(ImmutableThingy)#1 (1) {
["foo":protected]=>
string(3) "bar"
}
string(3) "bar"
Fatal error: Uncaught Exception: <iframe width="420" height="315" src="https://www.youtube.com/embed/otCpCn0l4Wo?t=14" frameborder="0" allowfullscreen></iframe> in /in/cev6l:5
Stack trace:
#0 /in/cev6l(23): ImmutableThingy->__set('foo', 'baz')
#1 {main}
thrown in /in/cev6l on line 5
Process exited with code 255. - Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
- object(ImmutableThingy)#1 (1) {
["foo":protected]=>
string(3) "bar"
}
string(3) "bar"
Fatal error: Uncaught exception 'Exception' with message '<iframe width="420" height="315" src="https://www.youtube.com/embed/otCpCn0l4Wo?t=14" frameborder="0" allowfullscreen></iframe>' in /in/cev6l:5
Stack trace:
#0 /in/cev6l(23): ImmutableThingy->__set('foo', 'baz')
#1 {main}
thrown in /in/cev6l on line 5
Process exited with code 255.
preferences:
169.92 ms | 402 KiB | 209 Q