<?php
$a = '123';
function c()
{
global $a;
($d = $a) && ($a = "");
return $d;
}
function d()
{
global $a;
$d = $a && $a = "456";
return $d;
}
function e()
{
global $a;
$d = $a;
$a = "456";
return $d;
}
var_dump(c(), d(), e());
php7.4.21 && php7.4.28
string(3) "123"
bool(false)
string(0) "
需要使用phpdbg或者vld查看opcache
问题原因
- 优先级问题
$d = $a && $a = "456";
被解析成$d = ($a && $a = '456');