How to override built-in PHP function(s)?

前端 未结 2 2014
温柔的废话
温柔的废话 2020-12-01 16:25

I would like to override, let\'s say mysql_num_rows with let\'s say following:

$dataset = array(array(\'id\' => 1, \'name\' => \'Zlatan\',         


        
2条回答
  •  旧时难觅i
    2020-12-01 17:10

    I think it could be done like so:

    //First rename existing function
    rename_function('strlen', 'new_strlen');
    //Override function with another
    override_function('strlen', '$string', 'return override_strlen($string);');
    
    //Create the other function
    function override_strlen($string){
            return new_strlen($string);  
    }
    

    found it here

    Notice that every host must have http://php.net/manual/en/book.apd.php installed on the server.

    Edit

    Another way is to use namespaces

    
    

    Test it here

提交回复
热议问题