PHP:什么是语言构造,为什么我们需要它们? [英] PHP: What are language constructs and why do we need them?

查看:93
本文介绍了PHP:什么是语言构造,为什么我们需要它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断遇到类似这样的语句:

I keep coming across statements like:

  • "echo是一种语言构造,但 打印是一种功能,因此具有 返回值"
  • 模具是一种语言构造"
  • "echo is a language construct but print is a function and hence has a return value"
  • "die is a language construct"

我的问题是这些语言构造是什么,更重要的是我们为什么需要它们?

My question is what are these language constructs and more importantly why do we need them?

推荐答案

语言结构被硬编码到PHP语言中.他们没有按照正常规则比赛.

Language constructs are hard coded into the PHP language. They do not play by normal rules.

例如,每当您尝试访问不存在的变量时,都会收到错误消息.要在访问变量之前测试其是否存在,您需要查阅issetempty:

For example, whenever you try to access a variable that doesn't exist, you'd get an error. To test whether a variable exists before you access it, you need to consult isset or empty:

if (isset($foo))

如果isset是正常函数,则由于在访问$foo并将其传递给函数isset,因此也会在其中得到警告.由于isset是一种语言构造,因此可以正常工作而不会发出警告.这就是为什么文档在正常功能和语言构造之间做出清晰区分的原因.

If isset was a normal function, you'd get a warning there as well, since you're accessing $foo to pass it into the function isset. Since isset is a language construct though, this works without throwing a warning. That's why the documentation makes a clear distinction between normal functions and language constructs.

这篇关于PHP:什么是语言构造,为什么我们需要它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆