如何在 PHP 中给函数取别名? [英] How to alias a function in PHP?
本文介绍了如何在 PHP 中给函数取别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 PHP 中使用不同名称的函数别名?假设我们有一个名为 sleep
的函数.有没有办法创建一个名为 wait
的别名?
Is it possible to alias a function with a different name in PHP? Suppose we have a function with the name sleep
. Is there a way to make an alias called wait
?
现在我是这样做的:
function wait( $seconds ) {
sleep($seconds);
}
推荐答案
仅限 PHP 5.6+
从 PHP 5.6 开始 可以通过导入来给函数取别名:
PHP 5.6+ only
Starting with PHP 5.6 it is possible to alias a function by importing it:
use function sleep as wait;
文档中还有一个示例(参见函数别名").
这篇关于如何在 PHP 中给函数取别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文