我注意到下面的代码导致PHP 5.x和7中的不同消息:
if ('0xFF' == 255) {
echo 'Equal';
} else {
echo 'Not equal';
}
Run Code Online (Sandbox Code Playgroud)
试图在迁移指南和PHP文档中找到导致它的更改的描述,但找不到任何内容.可能它在某处,我只是错过了它.请你指点一下吗?谢谢!
我看的地方
我的 VS Code 不会从node_modules
.
我试图让它在两台 PC 和一台 Mac 上运行 - 结果是一样的:在我输入时没有建议导入,当我专注于一个符号并按Ctrl+.
/时没有选项Cmd+.
- 没有快速修复建议。
我尝试安装自动导入扩展 - 没有建议。
我阅读了有关“添加所有丢失的导入”的发行说明帖子,并尝试应用快捷方式 - 不走运,它没有做任何事情。
在这一点上我完全迷失了,我看到很多帖子有人问同样的问题,人们建议他们通过按 Ctrl+ 来使用 Quick Fix。但正如您在屏幕截图中看到的那样 - 它没有任何建议。
我正在使用 TypeScript,但我也用 JS 尝试过这个 - 不走运。
在屏幕截图上,我在 WSL 中运行我的应用程序,但我也在 Windows 和 macOS 上尝试了本机运行。
有任何想法吗?谢谢!
当你需要检查数组中是否有任何值时,如果没有 - 为变量设置默认值,你可以这样做
$authToken = isset($response['fbData']['authResponse']['accessToken']) ? $response['fbData']['authResponse']['accessToken'] : null;
Run Code Online (Sandbox Code Playgroud)
我想知道,有什么方法可以让它更具可读性吗?
有三元运算符的简短版本
$authToken = $sourceVar ?: null;
Run Code Online (Sandbox Code Playgroud)
这里不需要第二次重复源,但它不适用于数组,因为如果我将使用$response['fbData']['authResponse']['accessToken']
而不是$sourceVar
- 我将获得php警告消息.
我可以用 @
$authToken = @$response['fbData']['authResponse']['accessToken'] ?: null;
Run Code Online (Sandbox Code Playgroud)
我听说他们让"@"真的很快PHP 5.4
,但我还是不喜欢这个.
我可以使用这样的东西
$a = isset($response['fbData']['authResponse']['accessToken']) ?: null;
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我将得到TRUE作为结果,结果isset()
.
所以,也许有人知道,怎么做对了?
Upd1:推荐主题如何在PHP中创建新运算符?不是我的问题的答案,因为用户询问"如何更改PHP"并创建一个新的运算符.我不需要这个.有一些答案如何在没有PHP修改的情况下做类似的事情,但它们不适用于数组(我不能$response['fbData']['authResponse']['accessToken']
在函数中传递这样的东西,因为它会生成警告消息).
Upd2:问题解决了,感谢NikiC(见下面的评论).想法:如果我将数组元素作为链接传递,Php将不会生成警告消息,因此它让我们有机会使用这样的东西:
function myIsset (&$var, $defaultVal = null) {
return isset($var) ? $var : $defaultVal;
}
$authToken = myIsset($response['fbData']['authResponse']['accessToken']);
Run Code Online (Sandbox Code Playgroud)
UPD2 10/27/2015: PHP 7有一个新的令人敬畏的运算符??
(空合并运算符)完全解决了这个问题并且是最好的方法:它返回它的第一个操作数,如果它存在并且不是NULL; 否则返回第二个操作数.
$authToken = $response['fbData']['authResponse']['accessToken'] ?? …
Run Code Online (Sandbox Code Playgroud) df -h
表明只有71%的空间使用:
root@ip-xxx-xxx-xxx-xxx:/home/myuser# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 7.9G 5.3G 2.2G 71% /
udev 10M 0 10M 0% /dev
tmpfs 60M 88K 60M 1% /run
/dev/xvda1 7.9G 5.3G 2.2G 71% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 120M 0 120M 0% /run/shm
Run Code Online (Sandbox Code Playgroud)
但是,没有任何东西可以再创建文件,甚至MC
无法启动
#mc
Cannot create temporary directory /tmp/mc-root: No space left on device (28)
Run Code Online (Sandbox Code Playgroud)
Php无法创建文件
PHP Warning: fopen(/home/.../file.json): failed to open stream: No space
left on device in /webdev/www/..../my.php on …
Run Code Online (Sandbox Code Playgroud) 在测试期间,我需要做以下事情:
我的代码:
$this->byId('reg_email')->value('test@example.com');
$this->byId('reg_password')->value('seecret');
// No form here, so i can't just call submit()
// This click invokes ajax request
$this->byId('reg_submit')->click();
// Check page content (this page should appear after redirect)
$msg = $this->byCssSelector('h1')->text();
$this->assertEquals('Welcome!', $msg);
Run Code Online (Sandbox Code Playgroud)
问题
解决方案,我不喜欢:
sleep(3);
在内容检查之前添加.我不喜欢它,因为:
我想知道,有没有办法跟踪ajax请求+刷新并及时检查内容?
我的设置:
我正在尝试将请求代理到远程服务器,这就是我配置Nginx的方式
upstream myupstream {
server remote-hostname;
}
Run Code Online (Sandbox Code Playgroud)
...
location ~ ^/(v1|v2|v3)/.*$ {
proxy_pass https://myupstream;
# also tried these options:
# proxy_ssl_server_name on;
# proxy_ssl_verify off;
# proxy_set_header Host <remote-hostname-here>;
# proxy_set_header X_FORWARDED_PROTO https;
}
Run Code Online (Sandbox Code Playgroud)
结果,我看到错误502页,并且该记录在error.log中
2018/11/10 19:41:38 [error] 8410#8410: *1 SSL_do_handshake() failed
(SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number)
while SSL handshaking to upstream, client: 127.0.0.1, server: <my-web-host-here>,
request: "GET /v1/some/page HTTP/1.1",
upstream: "https://<my-web-host-ip-here>:80/v1/some/page",
host: "<my-web-host-here>"
Run Code Online (Sandbox Code Playgroud)
是什么原因造成的?
注意:此Nginx代理位于我的本地计算机上。