Fatal error: Cannot use isset() on the result of an expression

Musa Muaz

When coding with isset i am getting an fatal error.I have searched stackoverflow but results are not satisfactory.

I am getting

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)

My codes are

if (!isset( $size || $color )) {
    $style = '';    
}else{
    $style = 'font-size : ' . $size . ';color:' . $color;   
}
Steve

As mentioned in the comments (and the error message), you cannot pass the result of an expression to isset.

You can use multiple isset calls, or reverse the logic of your if/else block and pass multiple parameters to isset, which i think is the cleanest solution:

//true if both are set
if(isset($size, $color)) {
    $style = 'font-size : ' . $size . ';color:' . $color;
}else{
    $style = '';
}

You can clean this up a little further by setting the default value first, thus avoiding the need for an else section:

$style = '';
if(isset($size, $color)) {
    $style = 'font-size : ' . $size . ';color:' . $color;
}

You could even use a ternary, though some people find them harder to read:

$style = isset($size, $color) ? 'font-size : ' . $size . ';color:' . $color : '';

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

GoogleTest `expression result unused'

来自分类Dev

How to print fatal error in code editor?

来自分类Dev

matplotlib fatal error ft2

来自分类Dev

XCode Warning "Expression Result Unused" for mathematical statement

来自分类Dev

if(isset(a,b)) 和 if(isset(a) &&isset(b)) 的区别

来自分类Dev

Arduino Arithmetic error negative result

来自分类Dev

Taking a datetime field into primary key throws fatal error

来自分类Dev

Fatal Error: Array Index out of range in Swift Xcode6

来自分类Dev

PDO - Fatal error: Call to a member function fetch() on a non-object

来自分类Dev

Creating hierarchical JSON result from multiple tables using linq expression

来自分类Dev

当我刷新页面时,错误提示:“不能在表达式的结果上使用isset()(您可以使用“ null!== expression”代替)”

来自分类Dev

How to use a SUM result in the same query?

来自分类Dev

error: expression must have integral or enum type

来自分类Dev

C , Error: Expression must be a modifiable lvalue

来自分类Dev

Error: Error: Cannot find module ' in angular js?

来自分类Dev

isset()和__isset()有什么区别?

来自分类Dev

isset()和__isset()有什么区别?

来自分类Dev

Cannot get expected result for Spring4D cryptography examples

来自分类Dev

Laravel How to Isset _GET

来自分类Dev

Laravel检查输入isset

来自分类Dev

isset()仅返回true

来自分类Dev

isset() is returning only true

来自分类Dev

DateInterval属性和isset()

来自分类Dev

if(isset)$ _ POST麻烦

来自分类Dev

执行顺序ISSET与JQUERY

来自分类Dev

控件未输入if(isset()))

来自分类Dev

使用isset进行校正?

来自分类Dev

简化多个isset

来自分类Dev

isset()多字段错误

Related 相关文章

热门标签

归档