3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getOptionOrElse(array $options, string $key, $else = false) { if (key_exists($key, $options) && $options[$key]['value'] !== '' && $options[$key]['value'] !== null) { return $options[$key]['value']; } return $else; } $abo_options = [ 'gedeelde bundel - belminuten per maand' => ['value' => 200], 'gedeelde bundel - sms per maand' => ['value' => 200], 'gedeelde bundel - mb per maand' => ['value' => 200] ]; //$minuten_sms_mb_amount = getOptionOrElse($abo_options,'gedeelde bundel - belminuten per maand', 0); //$minuten_sms_mb_amount += getOptionOrElse($abo_options,'gedeelde bundel - sms per maand', 0); //$minuten_sms_mb_amount += getOptionOrElse($abo_options,'gedeelde bundel - mb per maand', 0); $minuten_sms_mb_amount = getOptionOrElse($abo_options,'gedeelde bundel - belminuten per maand', 0); $minuten_sms_mb_amount += $minuten_sms_mb_amount === 0 ? getOptionOrElse($abo_options,'gedeelde bundel - sms per maand', 0) : 0; $minuten_sms_mb_amount += $minuten_sms_mb_amount === 0 ? getOptionOrElse($abo_options,'gedeelde bundel - mb per maand', 0) : 0; echo "amount: {$minuten_sms_mb_amount}";
based on j7P5r
Output for hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
amount: 200
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 2 passed to getOptionOrElse() must be an instance of string, string given, called in /in/NZ1qX on line 22 and defined in /in/NZ1qX on line 3
Process exited with code 255.