English 中文(简体)
以往使用的超重职能
原标题:Override previously used functions

I m正在与PHP一道制造一个ir子。 在发展过程中,我希望能够有活力地装载和卸载各类/功能。

你们知道,购买力平价是固定的。

页: 1

www.un.org/Depts/DGACM/index_spanish.htm

class stuff {

    function stuff() { echo  this ; }

    function replaceFunction() {
        remove(stuff);
        add(stuff);
    }
}
$stuff = new stuff();

Next

I edit a function:

function stuff() { echo  that ; }

理想的情况是,现在它经过编辑后,我必须做的是取代职能,以更新旧职能。

我如何使这项工作真正发挥作用?

最佳回答

如果你唯一需要的是具有职能的一个类别,而且你希望能够通过启动<条码>替代功能<<<>代码>的功能,就能够交换该类别或类似职能:

class stuff {
    private $callback;
    public function __construct()
    {
        $this->callback = array($this,  stuff );
    }

    public function __invoke()
    {
        call_user_func($this->callback);
    }   

    private function stuff() { echo  This ; }

    function replace($function) {
        $this->callback = $function;
    }
}


$stuff = new stuff;

$stuff(); # original function

$stuff->replace(function() { echo  That ; });

$stuff(); # replaced function

或短文:

$stuff = function() {echo  This ;};

$stuff(); # original function

$stuff = function() {echo  That ;};

$stuff(); # replaced function

The class has the benefit that you have more control about assigning and invoking the function.

问题回答

Maybe you can remove the functions first

runkit_function_remove ( string $funcname );

使用<条码>——机体()来检查功能是否已经存在。

EDIT:

class stuff {
    function replaceFunction() {
        runkit_function_remove( stuff );
        function stuff() { echo  New stuff ; }
    }
}
$stuff = new stuff();
$stuff->replaceFunction();




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签