在 PHP7+ 中有这个新的“空合并运算符”。- http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op 它说:
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
Run Code Online (Sandbox Code Playgroud)
在这种情况下,为什么此代码会导致错误/通知:
$username = (int)($_GET['user']) ?? 'nobody';
Run Code Online (Sandbox Code Playgroud)
注意:未定义索引:用户
这是预期的行为(如果是这样,它是否违背了该运算符的目的)?更改(int)为(string)等时的类似通知。