Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

直接对表达式判空编译成isset会报错 #126

Open
shirookie opened this issue Jul 31, 2020 · 1 comment
Open

直接对表达式判空编译成isset会报错 #126

shirookie opened this issue Jul 31, 2020 · 1 comment

Comments

@shirookie
Copy link

问题描述

如果源码里这样写:

a() !== undefined;

编译出来的结果是:

isset(a());

运行时就会报错,如下

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /path/to/file.php

临时方案

通过改源码,有两种方式可解

方法1:反过来判断

源码:

undefined !== a();

编译结果:

null !== a();

方法2:先赋值给变量,再判断

源码:

const b = a();
return b !== undefined;

编译结果:

$b = a();
return isset($b);

期望

直接编译成:新建一个临时变量,对临时变量执行 isset

大概就像 babel 对剪头函数进行转换的时候,在函数最外面先建个变量指向当前 this 那种

@cxtom
Copy link
Collaborator

cxtom commented Jul 31, 2020

欢迎pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants