是否可以替换 php 中的函数(例如邮件)并使其执行其他操作? [英] Is it possible to replace a function in php (such as mail) and make it do something else?

查看:12
本文介绍了是否可以替换 php 中的函数(例如邮件)并使其执行其他操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 PHP 重写一个函数(假设是 mail() 函数),并且希望从现在开始调用 mail() 时,它将加载我的 mail() 版本而不是默认版本php 版本.这在 php 中可能吗?

我想这样做的原因是因为我有数千行代码调用 mail() 并且我不想重写所有代码.

为了将来参考,在计算机编程中,当你做这样的事情时,它叫什么?

解决方案

有一个扩展允许您覆盖函数.它旨在用于调试,但我想您可以根据需要使用它.看一看:

http://www.php.net/manual/en/function.override-function.php

如果您希望在您的版本中调用原始函数,请务必阅读以下评论:http://no.php.net/manual/en/function.override-function.php#50821

I want to rewrite a function in PHP (let's say the mail() function), and want to make it so when I call mail() from now on, it will load my version of mail() and not the default php version. Is this possible in php?

The reason I want to do this is because I have thousands of lines of code which call mail() and I don't want to rewrite all of them.

Also for future reference, in computer programming, what is it called when you do something like this?

解决方案

There is an extension that allows you to override functions. It is meant to be used for debugging, but I guess you can use it for your needs. Take a look:

http://www.php.net/manual/en/function.override-function.php

If you wish to call the original function within your version, make sure you read this comment: http://no.php.net/manual/en/function.override-function.php#50821

这篇关于是否可以替换 php 中的函数(例如邮件)并使其执行其他操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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