3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LegacyBank { protected $clients; protected $balances; public function __construct($clients, $balances) { $this->clients = $clients; $this->balances = $balances; } public function getClientIndex($name) { foreach ($clients as $key => $client) { if ($client == $name) { $id = $key; break; } } return $id; } public function getBalance($index) { return $this->balances[$index]; } public function setBalance($index, $value) { $this->balances[$index] = $value; } public function processTransfer($id1, $sum, $id2) { $this->balances[$id1] = $this->balances[$id1] - $sum; $this->balances[$id2] = $this->balances[$id2] + $sum; } } interface POOClient{ public function deposit($sum); public function verifyAccount(); public function transfer($sum, $destination); } class SimpleClient implements POOClient{ protected $name; protected $legacyBank; protected $index; public function __construct($name, $legacyBank) { $this->name = $name; $this->legacyBank = $legacyBank; $this->index = $legacyBank->getClient($name); } public function deposit($sum) { $legacybank->setBalance($this->index, $sum); } public function verifyAccount() { $sum = $legacyBank->getBalance($this->index); return $sum; } public function transfer($sum, $destination) { $toIndex = $legacyBank->getClient($destination); $this->legacyBank->setBalance($toIndex, $sum); $oldBalance = $this->legacybank->getBalance($this->index); $this->legacyBank->setBalance($this->index, $oldBalance - $sum); } } $clients = array( '0' => 'Ion', '1' => 'Maria', '2' => 'Costel' ); $balances = array( '0' => 1000, '1' => 1400, '2' => 1300 ); $legacyBank = new LegacyBank($clients, $balances); $clientObject = new SimpleClient('Ion', $legacyBank); print_t($clientObject);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 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.6
Fatal error: Uncaught Error: Call to undefined method LegacyBank::getClient() in /in/9u9W7:52 Stack trace: #0 /in/9u9W7(90): SimpleClient->__construct('Ion', Object(LegacyBank)) #1 {main} thrown in /in/9u9W7 on line 52
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Call to undefined method LegacyBank::getClient() in /in/9u9W7 on line 52
Process exited with code 255.

preferences:
182.04 ms | 402 KiB | 183 Q