run code in 300+ PHP versions simultaneously
<?php /* assuming you MUST start with your json string, here's my review: * $i is a useless declaration. You don't use it, so lose it. * Initialise the $options array by populating it with parent::getOptions(). * In html, when an <option> tag has identical values in its value attribute and its text, the value attribute can be safely removed without any consequence to form or js behaviours. * I am going to assume/hope that the value element is not required to populate an option tag. * See you on Tuesday for https://www.meetup.com/Joomla-Users-Group-Brisbane/events/xggwjrybcjbvb/ */ // COMPLETELY THEORETICAL / UNTESTED... public function getOptions() { $json = '{"items":[{"aliases":["http://www.stackoverflow.com","http://facebook.stackoverflow.com"],"api_site_parameter":"meta.stackoverflow"~}'; $sites = json_decode($json, true); $options = parent::getOptions(); foreach($sites['items'] as $site) { $options[] = ['text' => $site['api_site_parameter']]; } return $options; }
Output for 7.2.0 - 7.2.31, 7.3.0 - 7.3.18, 7.4.0 - 7.4.6
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /in/mc84g on line 13
Process exited with code 255.

45.76 ms | 456 KiB | 5 Q