3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Monad boxing integer side effects * * @package default * @subpackage default * @author Federico Marani **/ class IntegerBox { /** * undocumented function * * @return void **/ public function __construct($value) { $this->value = $value; $this->isNaN = false; $this->infinite = false; } /** * undocumented function * * @return void **/ public static function identity($unboxedInt) { return new IntegerBox($unboxedInt); } /** * undocumented function * * @return void **/ public static function bind($boxedInt, $function) { $newBox = @$function($boxedInt); if ($newBox->value == null) $newBox->infinite = true; return $newBox; } /** * undocumented function * * @return void **/ public function __toString() { if ($this->isNaN) return "NaN"; if ($this->infinite) return "Infinite"; return strval($this->value); } } // END class IntegerBox $plusOne = function($x) { return IntegerBox::identity($x->value + 1); }; $one = IntegerBox::identity(1); $two = IntegerBox::bind($one, $plusOne); print "$two\n"; $divideByZero = function($x) { return IntegerBox::identity(bcdiv($x->value, 0)); }; $newVal = IntegerBox::bind($one, $divideByZero); print "$newVal\n";
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property IntegerBox::$value is deprecated in /in/A3r6E on line 18 Deprecated: Creation of dynamic property IntegerBox::$isNaN is deprecated in /in/A3r6E on line 19 Deprecated: Creation of dynamic property IntegerBox::$infinite is deprecated in /in/A3r6E on line 20 2 Fatal error: Uncaught DivisionByZeroError: Division by zero in /in/A3r6E:68 Stack trace: #0 /in/A3r6E(68): bcdiv('1', '0') #1 /in/A3r6E(39): {closure}(Object(IntegerBox)) #2 /in/A3r6E(70): IntegerBox::bind(Object(IntegerBox), Object(Closure)) #3 {main} thrown in /in/A3r6E on line 68
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:
43.03 ms | 402 KiB | 8 Q