php – {}标记回显“{$e-> getMessage()}”
发布时间:2020-12-13 22:20:44 所属栏目:PHP教程 来源:网络整理
导读:我读到了这个 Article 我想知道这部分: try { //First try getting our user numero uno $user = new User(1); //Then,let's try to get the exception $user2 = new User('not numeric');} catch( Exception $e ) { echo "Donkey Kong has caught an excep
我读到了这个
Article
我想知道这部分: try { //First try getting our user numero uno $user = new User(1); //Then,let's try to get the exception $user2 = new User('not numeric'); } catch( Exception $e ) { echo "Donkey Kong has caught an exception: {$e->getMessage()}"; } 为什么必须在括号中涵盖{$e-> getMessage()}? 我知道如果我们不放括号它会显示错误,但我想要的是得到解释为什么需要括号.
解决方法
这与这是一个复杂的表达这一事实有关.如果您不包括支架,即:
echo "Donkey Kong has caught an exception: $e->getMessage()"; …那么PHP如何知道您要输出的变量?您可能正在尝试执行以下任何操作: >输出$e的值,后跟字符串“ – > getMessage()” 将括号放在完整表达式周围会告诉PHP需要计算并包含在字符串中的完整表达式. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |