3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace StockCommandNS; interface Order { public function execute(); } // Receiver class. class StockTrade { public function buy() { print("You want to buy stocks"); } public function sell() { print("You want to sell stocks "); } } // Invoker. class Agent { private \SplQueue $ordersQueue; public function __construct() { $this->ordersQueue = new \SplQueue(); } public function placeOrder(Order $order) { $this->ordersQueue->push($order); $order->execute($this->ordersQueue->shift()); } } //ConcreteCommand Class. class BuyStockOrder implements Order { private StockTrade $stock; public function __construct(StockTrade $st) { $this->stock = $st; } public function execute() { $this->stock->buy(); } } //ConcreteCommand Class. class SellStockOrder implements Order { private StockTrade $stock; public function __construct(StockTrade $st) { $this->stock = $st; } public function execute() { $this->stock->sell(); } } class MyCommand implements Order { private $action; public function __construct($action) { $this->action = $action; } public function execute() { $this->action->run(); } } $stock = new StockTrade(); $bsc = new BuyStockOrder($stock); $ssc = new SellStockOrder($stock); $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 stocksYou 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:
68.54 ms | 401 KiB | 8 Q