downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

rename_function> <apd_set_session
[edit] Last updated: Fri, 23 Mar 2012

view this page in

override_function

(PECL apd >= 0.2)

override_functionYerleşik işlevleri geçersiz kılar

Açıklama

bool override_function ( string $işlev_ismi , string $işlev_değiştirgeleri , string $işlev_kodu )

Simge tablosunda değişiklik yaparak yerleşik işlevleri geçersiz kılar.

Değiştirgeler

işlev_ismi

Geçersiz kılınacak işlev.

işlev_değiştirgeleri

Virgülle ayrılmış dizgeler halinde işlev değiştirgeleri.

Genellikle bu değiştirgeleri ve işlev_kodu değiştirgelerini tek tırnakla sınırlanmış dizge olarak geçirmek isteyeceksiniz. Tek tırnaklı dizge kullanımının sebebi değişken isimlerinin işlenmesini engellemektir, aksi durumda, çift tırnak kullanırsanız değişken isimlerinde önceleme karakteri kullanmanız gerekir (\$değişken gibi).

işlev_kodu

İşlevin yeni kodu.

Dönen Değerler

Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.

Örnekler

Örnek 1 - override_function() örneği

<?php
override_function
('test''$a,$b''echo "DNM 123"; return $a * $b;');
?>



rename_function> <apd_set_session
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes override_function
taher at unixwars dot com 28-Nov-2008 08:08
I had the same problem and, since the __overriden__() name is hardcoded, I simply ended up renaming that one. I use it like this:

<?php
function _dbslayer_map()
{
   
$substs = array(
       
'mysql_connect' => 'dbslayer_mysql_connect($host, $user, $pass, $new_link, $client_flags)',
       
'mysql_fetch_array' => 'dbslayer_mysql_fetch_array($result, $result_type)',
       
'mysql_query' => 'dbslayer_mysql_query($query, $link_identifier)'
           
);

   
$args = array(
       
'mysql_connect' => '$host = NULL, $user = NULL, $pass = NULL, $new_link = false, $client_flags = 0',
       
'mysql_fetch_array' => '&$result, $result_type = MYSQL_BOTH',
       
'mysql_query' => '$query, $link_identifier = DEFAULT_LINK'
           
);

    foreach (
$substs as $func => $ren_func) {
       
override_function($func, $args[$func], "return $substs[$func];");
             
rename_function("__overridden__", $ren_func);
      }
}
?>

So far, so good.
pagan at o2 dot pl 24-Oct-2008 12:34
There is not chance to override 2 or more functions, because of the error:
Fatal error: Cannot redeclare __overridden__()
rojaro at gmail dot com 20-Sep-2005 12:13
Since Apache 1 & 2 use diffrent methods (Unicode vs. UTF8) on Win32 platforms to encode urls, i've implemented the following workaround to get around this "bug" (which is actually known behaviour and wont get fixed). This workaround is really usefull when writing PHP scripts which have to work on all platforms (Windows, Linux, BSD etc.), must process URLs and must work under both Apache versions.

<?php
$httpd
= explode(' ', $_SERVER['SERVER_SOFTWARE']);
if(
substr($httpd[0], 0, 6)=='Apache' && substr($httpd[0], 7, 1)==2 && $httpd[1]=='(Win32)')
{
  if(isset(
$_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = str_replace('%2F', '/', rawurlencode(utf8_decode(rawurldecode($_SERVER['REQUEST_URI']))));
  if(isset(
$_SERVER['REDIRECT_URL'])) $_SERVER['REDIRECT_URL'] = str_replace('%2F', '/', rawurlencode(utf8_decode(rawurldecode($_SERVER['REDIRECT_URL']))));
 
override_function('urlencode', '$url', 'return str_replace("%2F", "/", rawurlencode(utf8_encode($url)));');
}
?>
php at undeen dot com 10-Mar-2005 12:07
I thought the example was not very helpful, because it doesn't even override the function with another function.
My question was: If I override a function, can I call the ORIGINAL function within the OVERRIDING function?
ie, can I do this:
<?php
override_function
('strlen', '$string', 'return override_strlen($string);');
function
override_strlen($string){
        return
strlen($string); 
}
?>
The answer: NO, you will get a segfault.

HOWEVER, if you use rename_function to rename the original function to a third name, then call the third name in the OVERRIDING function, you will get the desired effect:
<?php
rename_function
('strlen', 'new_strlen');
override_function('strlen', '$string', 'return override_strlen($string);');

function
override_strlen($string){
        return
new_strlen($string); 
}
?>

I plan to use this functionality to generate log reports every time a function is called, with the parameters, time, result, etc... So to wrap a function in logging, that was what I had to do.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites