3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on 72JKM
Output for 7.0.0 - 7.3.0alpha1
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.3.19 - 5.6.28
Fatal error: Call to undefined method LegacyBank::getClient() in /in/9u9W7 on line 52
Process exited with code 255.