[PHP编程] PHP重新定义系统或用户函数的方法

[复制链接]
发表于 2023-1-6 13:13:49
这是我自己写的一个PHP-Mock类,参考了GitHub上的一个项目。该PHP-Mock类可以在指定的命名空间中重新定义指定的函数,支持系统函数和用户自定义函数,但不支持公共命名空间。使用方法示例:


require 'phpmock.php';
use phpmock\Mock;

// 以下是让app\controller\home命名空间下的file_get_contents函数都返回“123456”
$func = function($url){
        return '123456';
}
Mock::builder('\\app\\controller\\home', 'file_get_contents', $func);

(This is a PHP-Mock class written by myself, referring to a project on GitHub. The PHP-Mock class can redefine the specified function in the specified namespace, supports system functions and user-defined functions, but does not support public namespaces. Example of how to use:


require 'phpmock.php';
use phpmock\Mock;

// The following is to let the file_get_contents function under the app\controller\home namespace return "123456"
$func = function($url){
return '123456';
}
Mock::builder('\\app\\controller\\home', 'file_get_contents', $func);)

[下载]13135043523.rar




上一篇:一个可以在线解密qmc、ncm等音乐加密格式的网站
下一篇:多站点音乐搜索器最新修复版源码

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表