3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace StockExample; interface Order { public function execute(); } class Stock { public function buy(): callable { return function () { echo "You want to buy stocks via callable function" . PHP_EOL; }; } public function sell(): callable { return function () { echo "You want to sell stocks via callable function" . PHP_EOL; }; } } class MyCommand implements Order { private $action; public function __construct(callable $action) { $this->action = $action; } public function execute() { // Option 1) use call_user_function call_user_func($this->action); // Option 2) define it as a variable and call it by adding `()` //$action = $this->action; //$action(); } } // example with a callable function $stock = new Stock(); $bsc = new MyCommand($stock->buy()); $ssc = new MyCommand($stock->sell()); $bsc->execute(); $ssc->execute();
Output for git.master, git.master_jit, rfc.property-hooks
You want to buy stocks via callable function You want to sell stocks via callable function

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:
173.99 ms | 405 KiB | 5 Q