3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Condition { var $causedNext = false; var $cause = null; public function __construct($at, $next = null) { $this->at = $at; $this->next = $next; } public function evalCondition() { $this->causedNext = false; $result = $this->actualEval(); if ($result !== false && $this->next) { $result = $this->next->evalCondition(); if ($result === false) $this->causedNext = true; } return $result; } public function actualEval() { return false; } public function getCause() { return $this->causedNext ? $this->next->getCause() : $this->cause; } } class Condition1 extends Condition { public function __construct($at, $next = null) { parent::__construct($at, $next); $this->cause = "cause 1"; } public function actualEval() { return $this->at->condition1; } } class Condition2 extends Condition { public function __constructor($at, $next = null) { parent::__constructor($at, $next); $this->cause = "cause 2"; } public function actualEval() { return $this->at->condition2; } } class X { var $condition1 = false; var $condition2 = false; public function __construct($c1, $c2) { $this->condition1 = $c1; $this->condition2 = $c2; } protected function check(\Closure $callback) { $condition = new Condition1( $this, new Condition2($this) ); if (!$condition->evalCondition()) { $this->log($condition->getCause()); } else return $callback(); $this->cleanup(); return null; } public function doSomething() { $this->check(function () { return $this->reallyDoSomething(); }); } public function reallyDoSomething() { echo "Done!"; } public function cleanup() { echo "> cleanup.\n"; } public function log($str) { echo "> $str\n"; } } echo "f, f\n"; $x = new X(false, false); $x->doSomething(); echo "f, t\n"; $x = new X(false, true); $x->doSomething(); echo "t, f\n"; $x = new X(true, false); $x->doSomething(); echo "t, t\n"; $x = new X(true, true); $x->doSomething();
Output for git.master, git.master_jit, rfc.property-hooks
f, f Deprecated: Creation of dynamic property Condition2::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition2::$next is deprecated in /in/8T21V on line 10 Deprecated: Creation of dynamic property Condition1::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition1::$next is deprecated in /in/8T21V on line 10 > cause 1 > cleanup. f, t Deprecated: Creation of dynamic property Condition2::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition2::$next is deprecated in /in/8T21V on line 10 Deprecated: Creation of dynamic property Condition1::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition1::$next is deprecated in /in/8T21V on line 10 > cause 1 > cleanup. t, f Deprecated: Creation of dynamic property Condition2::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition2::$next is deprecated in /in/8T21V on line 10 Deprecated: Creation of dynamic property Condition1::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition1::$next is deprecated in /in/8T21V on line 10 > > cleanup. t, t Deprecated: Creation of dynamic property Condition2::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition2::$next is deprecated in /in/8T21V on line 10 Deprecated: Creation of dynamic property Condition1::$at is deprecated in /in/8T21V on line 9 Deprecated: Creation of dynamic property Condition1::$next is deprecated in /in/8T21V on line 10 Done!

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:
34.12 ms | 405 KiB | 8 Q