We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
通常变量名的构成都是有限制的,比如要避开keyword。 但PHP有个小trick,你可以用 ${'any string can be used'} = true;。
${'any string can be used'} = true;
于是我最近在改进编译jedi到PHP的代码时,就用了这个方式。
不料就踩坑了……
${'test'} = 'this is ok'; $x = function () use ($test) {}; // this is ok... $x = function () use (${'test'}) {}; // this is NOT ok...
爆PHP语法错误。
这到底是为啥呢……
---- 无辜的分割线 ----
原来这个trick的本源就是“变量变量”(饶舌,好吧,合理的翻译是“可变变量”),比如:
$a = 'b'; $b = 'WTF'; echo $$a;
而 $$a 和 ${'test'} 其实都只是${expression}的特例而已。
$$a
${'test'}
${expression}
use(...) 构造中只接受真正的 symbol 从实现的角度考虑倒也是可以理解的。不过从一致性的角度考虑,稍微花点力气让 use(...) 支持可变变量也不是做不到。只能说PHP一贯坑,这个真也不算什么了。
use(...)
BTW,亚一程有个 use 别名的提案(https://wiki.php.net/rfc/useas ),但是貌似弃坑了。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
通常变量名的构成都是有限制的,比如要避开keyword。
但PHP有个小trick,你可以用
${'any string can be used'} = true;
。于是我最近在改进编译jedi到PHP的代码时,就用了这个方式。
不料就踩坑了……
爆PHP语法错误。
这到底是为啥呢……
---- 无辜的分割线 ----
---- 无辜的分割线 ----
---- 无辜的分割线 ----
---- 无辜的分割线 ----
---- 无辜的分割线 ----
---- 无辜的分割线 ----
---- 无辜的分割线 ----
原来这个trick的本源就是“变量变量”(饶舌,好吧,合理的翻译是“可变变量”),比如:
而
$$a
和${'test'}
其实都只是${expression}
的特例而已。use(...)
构造中只接受真正的 symbol 从实现的角度考虑倒也是可以理解的。不过从一致性的角度考虑,稍微花点力气让use(...)
支持可变变量也不是做不到。只能说PHP一贯坑,这个真也不算什么了。BTW,亚一程有个 use 别名的提案(https://wiki.php.net/rfc/useas ),但是貌似弃坑了。
The text was updated successfully, but these errors were encountered: