run code in 200+ php & hhvm versions
Bugs & Features
<?php function parseDbString(string $value = 'Looking for a good {{ $pippo }}'){ $pippo='Pizza'; return preg_replace_callback('/{{(.*?)}}/', function($res) use ($pippo) { return "${trim($res[1])}"; // $val=${trim($res[1])}; Returns "Undefined variable: $pippo" $val=${trim($res[1])}; // Returns "Looking for a good Pizza" return isset($val) ? $val : $res[0]; },$value); } var_dump(parseDbString());
based on 6F19b
Output for 7.0.28 - 7.3.0rc3
Notice: Undefined variable: $pippo in /in/D2PG7 on line 6 string(19) "Looking for a good "
Output for 5.6.38
Fatal error: Default value for parameters with a class type hint can only be NULL in /in/D2PG7 on line 3
Process exited with code 255.