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 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
You want to buy stocksYou want to sell stocks
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 You want to buy stocksYou want to sell stocks
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting function (T_FUNCTION) or const (T_CONST) in /in/iIHn9 on line 25
Process exited with code 255.

preferences:
158.61 ms | 402 KiB | 182 Q