PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousftp_systypecall_user_func_arraynext
Last updated: Tue, 09 Jul 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

XXXIV. Fonctions

Ces fonctions effectuent les manipulations li�es � la gestion des fonctions.

Table des mati�res
call_user_func_array --  Appelle une fonction utilisateur avec les param�tres rassembl�s en tableau
call_user_func --  Appelle une fonction utilisateur
create_function -- Cr�e une fonction anonyme (style lambda)
func_get_arg --  Retourne un �l�ment de la liste des arguments
func_get_args --  Retourne les arguments d'une fonction sous forme de tableau
func_num_args --  Retourne le nombre d'arguments pass� � la fonction
function_exists --  Indique si une fonction est d�finie.
get_defined_functions --  Liste toutes les fonctions d�finies
register_shutdown_function --  Enregistre une fonction pour ex�cution � l'extinction
register_tick_function --  Enregistre une fonction ex�cut�e � chaque tick
unregister_tick_function --  Annule la fonction ex�cut�e � chaque tick
User Contributed Notes
Fonctions
add a note about notes
[email protected]
23-Aug-2002 08:49

You can do some kind of overloading functions in PHP using "function_exists".

Let's suppose you want a script to call plugins that are php files and you want the plugins to "override" behaviours that if not overriden are used by default.

You might for example write a "mySQL table viewer" which displays a table and it "opens a table", "dumps the header", "dumps row-by-row" and then "closes the table".

Let's suppose you want a plugin for "Stocks" which prints negative stocks in red, so you want to override the "dumping row-by-row" to do that behaviour. Instead you do not want to have all the "default behaviour" repeated in the plugin.

You may then do the following:

1) Define a default plugin (ex: "default.php"

2) Write all your functions in default.php to open, dump and close, but add them a suffix:

open_table_default()
dump_header_default()
dump_row_default()
close_table_default()

3) Call your functions with a wrapper: Insetad of this:
open_table() or open_table_default() write this:

plugincall("open_table");

4) Then write a function called plugincall which uses function_exists() to see if you call one or the other function:

function plugincall($desired_function_name)
{

if( function_exists( $desired_function_name))
{
//Call the plugin
//Note the $ before the name
$desired_function_name()
}
else
{
$desired_function_name = $desired_function_name . "_default";
if( function_exists($desired_function_name))
{
//Call the default
//Note the $ before the name
$desired_function_name()
}
else
{
// Nor the plugin nor the default were defined
}
}

So, now, if the require_once(plugin.php) contains a function called "open_table()", it will be used. Instaed, "open_table_default()" will be used.

It's not like overloading functions, but it is very useful to write scripts ampliable by other programmers: If they write a function, it is used, if not, the default is used.

See ya!
Xavier Montero.

add a note about notes
previousftp_systypecall_user_func_arraynext
Last updated: Tue, 09 Jul 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST