Here is an easy way to get the result:
<?php ob_start(); eval("if ('1' == '0') echo 'never'; else echo 'always';"); $xs = ob_get_contents(); ob_end_clean(); //echo $xs;
To get the return value of eval() , you need to return something inside the evaluated code, for example:
$xs = eval("return '1' == '0' ? 'never' : 'always';"); echo $xs; // echoes 'always'
source share