创建动态php函数并稍后运行 - 将其保存到变量 [英] Create dynamic php function and run it later - Save it to a variable

查看:113
本文介绍了创建动态php函数并稍后运行 - 将其保存到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使一个函数稍后运行。

Im trying to make a function to run it later.

在php 5.3.2-1中,它工作正常。但是在5.1.6中没有。

In php 5.3.2-1 it works fine. But in 5.1.6 it doesn't.

代码是:

$func = function(){                                                             
  echo "Hello!";                                                                
};                                                                              

echo "Before Hello";                                                            
$func();   

有没有人知道如何在5.1.6中模拟这个?

Does anyone knows how to emulate this in 5.1.6?

谢谢。

Eduardo

推荐答案

匿名自PHP 5.3起可用的功能。您不能在旧版本中使用它们。看看文档

Anonymous functions are available since PHP 5.3. You cannot use them in older versions. Take a look at the docs.

这篇关于创建动态php函数并稍后运行 - 将其保存到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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