3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace StockCommandNS; //Command interface interface Order { public function execute(); } //Receiver class class StockTrade { public function buy() { print("You want to buy stocks\n"); } public function sell() { print("You want to sell stocks\n"); } } //Invoker class class Agent { public function placeOrder(Order $order) { $order->execute($order); } } //ConcreteCommand Class class GenericOrder implements Order { private $action; public function __construct($action) { $this->action = $action; } public function execute() { call_user_func($this->action); } } $stock = new StockTrade(); $bsc = new GenericOrder([$stock, 'buy']); $ssc = new GenericOrder([$stock, 'sell']); $agent = new Agent(); $agent->placeOrder($bsc); // Buy Shares $agent->placeOrder($ssc); // Sell Shares
Output for git.master, git.master_jit, rfc.property-hooks
You want to buy stocks You want to sell stocks

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