php检查类方法是否存在的方法是,使用method_exists方法来检查,例如【(method_exists($directory,'read'));】。

本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
method_exists检查类的方法是否存在。如果 method_name 所指的方法在 object 所指的对象类中已定义,则返回 true,否则返回 false。
代码示例:
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>以上例程会输出:
立即学习“PHP免费学习笔记(深入)”;
bool(true)
示例2
<?php
var_dump(method_exists('Directory','read'));
?>以上例程会输出:
立即学习“PHP免费学习笔记(深入)”;
bool(true)
相关视频教程分享:php视频教程
以上就是php怎么检查类方法是否存在的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号