在PHP中创建不带括号的函数,例如"echo" [英] Creating functions without parentheses in PHP like 'echo'

查看:275
本文介绍了在PHP中创建不带括号的函数,例如"echo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何不错的方法用PHP编写函数,以便它们不需要在参数周围使用().

I was wondering if there is any nice way of writing functions in PHP so that they don't require ( ) around the parameters.

示例:

function sayThis($str) {
    echo $str;
}

sayThis "hi!!";

谢谢, 马特·穆勒(Matt Mueller)

Thanks, Matt Mueller

推荐答案

根本没有. "echo"更像是一个运算符,而不是一个函数,因此您实际上需要重写PHP解释器源代码,以引入类似这样的新函数".

There simply isn't. "echo" is more of an operator than a function, so you'd actually need to rewrite the PHP interpreter source in order to introduce new "functions" like those.

实际上,正如eyze正确指出的那样,"echo"的更准确术语是语言构造而不是运算符. http://php.net/manual/de/function.echo.php提供更多信息.

Actually, the more accurate term for "echo" is, as eyze has correctly pointed out, language construct rather than operator. http://php.net/manual/de/function.echo.php provides some more information.

这篇关于在PHP中创建不带括号的函数,例如"echo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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