【问题标题】:In PHP, what does the 'at' symbol before an L-value mean? [duplicate]在 PHP 中,L 值前的“at”符号是什么意思? [复制]
【发布时间】:2014-09-28 03:31:23
【问题描述】:

我能找到的一切都是指使用@ 符号作为表达式的前缀,例如:

$foo = @bar();

不是我在这里说的。我有一个语句,它使用 @ 符号作为 L 值的前缀,例如:

@$foo = bar();

这是什么意思?

(理想情况下,请将语义解释为将此语句的去糖化为不使用@ 符号的语句。)

【问题讨论】:

标签: php semantics


【解决方案1】:

@ 符号用于suppress error messages

PHP 支持一种错误控制运算符:at 符号 (@)。什么时候 添加到 PHP 中的表达式之前,任何可能出现的错误消息 由该表达式生成的将被忽略。

例如;

以下代码不会在屏幕上产生任何错误;

<?php

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

@$foo = $bar;

echo $foo;

但是,如果没有 @ 它会这样做;

注意:未定义变量:第 6 行 C:\xampp\htdocs\test\test.php 中的 bar

【讨论】:

  • 在作业的LHS上?
  • @Quentin:- 是的,我想是的(如果我错了,请纠正我)我读过这个:-PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
  • @R.T.等等——你是说它前面的表达式是$foo = bar()?所以代码解析为@($foo = bar());?这当然是一种解释。
  • @jameshfisher:- 确实!
猜你喜欢
  • 2015-03-06
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
  • 2013-10-06
  • 2012-07-02
  • 1970-01-01
  • 2021-06-19
相关资源
最近更新 更多