了解有关eval'd代码的许多意想不到的问题,但没有一个可以帮助我找到这个特定的部分:
@eval('$return=(bool)('. $test.');');
有什么想法吗?
显示错误的完整代码是
$notfound = TRUE;
if (isset($child['when'])) {
foreach ($child['when'] as $grandchild) {
$test = $this->build_mask($datatree, $grandchild['test'], $direction, $cindex, $clast, $ckey, TRUE, $carray);
$return = NULL;
@eval('$return=(bool)('. $test .');');
if ($return === TRUE) {
$notfound = FALSE;
$built[] = $this->build_mask($datatree, $grandchild['true'], $direction, $cindex, $clast, $ckey, $incode, $carray);
break;
}
}
}
答案 0 :(得分:3)
Use below code:-
$test = 'XXX';
eval('$return=(bool)$test;');
if($return){ // true
// do your stuff
}
You can simply write it as:-
$test = 'XXX';
$return=(bool)$test;
if($return){ // true
// do your stuff
}
OR use !empty() to avoid unnecessary type casting.
$test = 'XXX';
if(!empty($test)){ // true
// do your stuff
}
Suggestion:- Never use @ to hide your errors. You should ON your error_reporting in development mode.