3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Invariant{ private $value; private $check; private $description; function __construct($check, $description){ $this->check = $check; $this->description = $description; } function set($value){ $check = $this->check; if($check($value)){ $this->value = $value; }else{ trigger_error("Invariant ".$this->description." violated.", E_USER_ERROR); } } function get(){ return $this->value; } } class A{ protected $a; function __construct(){ $this->a = new Invariant(function($value){return $value > 100;}, '$this->a > 100'); } } class B extends A{ function __construct(){ parent::__construct(); $this->a->set(10); //error $this->a->set(101); //that's ok } } $b = new B();
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Invariant $this->a > 100 violated. in /in/vjBRG on line 17
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
126.98 ms | 405 KiB | 5 Q