function func() {
return 'hello,world!';
}
$myFunction = 'func';当我们创建了自定义函数,并且了解了可变函数的用法,为了确保程序调用的函数是存在的,经常会先使用function_exists判断一下函数是否存在。
同样的method_exists可以用来检测类的方法是否存在。
if (function_exists($myFunction )){
echo 'exists';
}类是否定义可以使用class_exists。
Serendipity是一个采用PHP实现的智能博客BLOG系统,Serendipity功能丰富,符合标准,基于BSDLicense开源。 Serendipity 2.1.3 更新日志:2018-08-16 *安全性:确保RSS的管理员配置和博客条目限制被解析为SQL查询的整数; *安全性:在“编辑条目”面板中防止XSS可能性; *安全性:禁止向多个人发送评论通知和邮件地址;这可用于批
93
class MyClass{
}
// 使用前检查类是否存在
if (class_exists('MyClass')) {
$myclass = new MyClass();
}PHP中有很多这类的检查方法,例如文件是否存在file_exists等。
$filename = 'test.txt';
if (!file_exists($filename)) {
echo $filename . ' not exists.';
}以上就是php 可变函数用法的理解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号