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

search for in the

register_shutdown_function> <function_exists
Last updated: Fri, 20 May 2011

view this page in

get_defined_functions

(PHP 4 >= 4.0.4, PHP 5)

get_defined_functionsDevuelve una matriz de todas las funciones definidas

Descripción

array get_defined_functions ( void )

Obtiene una matriz de todas las funciones definidas.

Valores devueltos

Devuelve una matriz multidimensional que contiene una lisata de todas las funciones definidas, tanto de las incluidas (internas) como las definidas por el usuario. Las funciones internas serán accesibles mediante $arr["internal"], y las definidas por el usuario usando $arr["user"] (véase el ejemplo de abajo).

Ejemplos

Example #1 Ejemplo de get_defined_functions()

<?php
function mifila($id$data)
{
    return 
"<tr><th>$id</th><td>$data</td></tr>\n";
}

$arr get_defined_functions();

print_r($arr);
?>

El resultado del ejemplo sería algo similar a:

Array
(
    [internal] => Array
        (
            [0] => zend_version
            [1] => func_num_args
            [2] => func_get_arg
            [3] => func_get_args
            [4] => strlen
            [5] => strcmp
            [6] => strncmp
            ...
            [750] => bcscale
            [751] => bccomp
        )

    [user] => Array
        (
            [0] => mifila
        )

)

Ver también



register_shutdown_function> <function_exists
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes get_defined_functions
rob at webdimension dot co dot uk 01-Apr-2011 04:48
A quick way of using this function:

<?php
// ALL USER DEFINED FUNCTIONS
$arr = get_defined_functions();
foreach (
$arr['user'] as $key => $value){
echo
$value.'<br />';
}
// ALL USER DEFINED FUNCTIONS

// ALL INTERNAL FUNCTIONS
$arr = get_defined_functions();
foreach (
$arr['internal'] as $key => $value){
echo
$value.'<br />';
}
// ALL INTERNAL FUNCTIONS
?>
gmdebby at gmail dot com 14-Jan-2011 09:28
Note : get_defined_functions return lowercase names on Windows 7 with WampServer 2.1
ChaosKaizer 10-Jul-2008 02:13
for user defined function

<?php
/**
 * @param string $function_name The user function name, as a string.
 * @return Returns TRUE if function_name  exists and is a function, FALSE otherwise.
 */
function user_func_exists($function_name = 'do_action') {
  
   
$func = get_defined_functions();
  
   
$user_func = array_flip($func['user']);
  
    unset(
$func);
  
    return ( isset(
$user_func[$function_name]) );  
}
?>
strrev xc.noxeh@ellij 04-Jun-2008 12:31
Please note that functions created with create_function() are not returned.
(However that might change in a later version)
spudinski at gmail dot com 01-Apr-2008 02:13
To search for a function.
<html>
<head>
<title>List of all Internal functions</title>
<style type="text/css">
body {
    background-color: #FFFFFF;
    color: #222222;
    font-size: 11px;
    font-family: arial, tahoma;
}
table {
    color: #222222;
    font-size: 11px;
    font-family: arial, tahoma;
}
tr.found {
    background-color: #66EE00;
    font-weight: bold;
}
a:link {
    color: #222222;
}
a:visited {
    color: #CCCCCC;
}
a:active {
    color: #444444;
}
a:hover {
    text-decoration: underline;
}
</style>
</head>
<body>
<p>
    <form method="GET">
    Search: <input type="text" name="search"><br>
    <input type="submit">
    </form>
</p>
<?php
   
if (!empty($_GET['search'])) {
        echo
'<p>' . '<a href="#' . $_GET['search'] . '">' .
       
'Goto ' . $_GET['search'] . '</a>' .
       
'<script type="text/javascript">
            window.onload = function() {
                document.location += "#'
. $_GET['search'] . '";
                return true;
            }
        </script>
        </p>'
;
    }
?>
<p>
    <table>
<?php
    $country
= 'us';
   
$functions = get_defined_functions();
   
$functions = $functions['internal'];
   
$num = 0;
    foreach(
$functions as $function) {
       
$num++;
        echo
'<tr ' . (($_GET['search'] == $function) ? 'class="found"' : '') . '><td>' .
       
number_format($num) . '</td><td>' . '<a name="' . $function . '" href="http://' . $country . '.php.net/' .
       
$function . '">' . $function . '</a>' . '</td></tr>';
    }
?>
    </table>
</p>
</body>
</html>
berchentreff at berchentreff dot de 31-Mar-2006 01:46
look at here, list all the defined function on your php-Version and give as well formatted output width links onto the php-manual:

<html><head>
<style type="text/css"><!--
li{font-family:Verdana,Arail,sans-serif;width:500px;margin-top:7px;}
a{padding:4px;}
a.a1{font-size:12px;background-color:#CCCCCC;color:#663300;}
a.a1:hover{background-color:#663300;color:#CCCCCC;}
a.a1:visited{background-color:#fff;color:#999;}
a.a1:visited:hover{background-color:#fff;color:#999;}
a.a0{font-size:12px;background-color:#CCCCFF;color:#663399;}
a.a0:hover{background-color:#663399;color:#CCCCFF;}
a.a0:visited{background-color:#ffC;color:#999;}
a.a0:visited:hover{background-color:#ffC;color:#999;}
--></style>
</head><body style="background-color:#999;">
<?php
$arr
= get_defined_functions();

foreach(
$arr as $zeile){
sort($zeile);$s=0;
foreach(
$zeile as $bzeile){
$s=($s)?0:1;
echo
"<li><a class='a".$s."'  href='http://de.php.net/".$bzeile."'>".$bzeile."</a></li>";}
}
?>
</body>
</html>
php dot net at schou dot dk 20-May-2003 09:47
Here is another example which list all the available functions and gives a link to the manual pages at the same time.

<?php
$manref
= "http://www.php.net/manual/en/function";
$arr = get_defined_functions();
while (list(
$type,$list) = each($arr)) {
        if (
$type == "internal" && is_array($list)) {
               
sort($list);
                foreach (
$list as $func) {
                        if (
$func == "_")
                               
$func2 = "gettext";
                        else
                               
$func2 = preg_replace("/_/", "-", $func);
                        echo
"<a href=\"$manref.$func2.php\">$func</a><br>\n";
                }
        }
}
?>
kaneccc at seznam dot cz 28-Mar-2003 12:30
I've written simple XML-RPC server which automatically registers all defined functions starting with "RPC_" prefix and found, that with PHP 2.4.3 on Win32 and Linux platforms function names are in lowercase so the xmlrpc_server_call_method() is case sensitive which is correct with XML, but not with PHP and get_functions_defined()

I also suggest changing the function to have flags/options to return internal, user or both functions only and starting with prefix such as:

<?php
// constants
define( 'xxx_INTERNAL', 0x1 );
define( 'xxx_USER', 0x2 );
define( 'xxx_BOTH', 0x3 );

// declaration
array get_functions_defined( int options, string prefix );
?>

with both arguments optional.

Johnnie
mIHATESPAMduskis at bates dot edu 21-Nov-2002 10:47
At least with PHP 4.2.3 on a GNU/Linux/Apache platform, get_defined_functions() returns user-defined functions as all-lower case strings regardless of how the functions are capitalized when they are defined.

Threw me for a loop.
peten at spam dot me dot not dot frontiernet dot net 02-Jun-2002 05:28
Here's a useful trick with the get_defined_functions function - show all available functions with a link to the documentation (you can even change the mirror it goes to):

<?php
 
// the php mirror
 
$php_host = "http://us2.php.net/";

 
// the number of cols in our table
 
$num_cols = 3;

 
$ar = get_defined_functions();
 
$int_funct = $ar[internal];
 
sort($int_funct);
 
$count = count($int_funct);
?>
<html>
 <head>
  <title>
   Available PHP Functions
  </title>
 </head>
 <body>
  <p>
   <?php print $count; ?> functions    
    available on
    <?php
     
print $_SERVER[SERVER_NAME];
    
?>
   (<a href="<?php print $php_host;?>"
    target="phpwin">php</a>
    version
    <?php print phpversion(); ?>)
  </p>
  <table align="center" border="2">
   <tr> 
<?php
 
for($i=0;$i<$count;$i++) {
   
$doc = $php_host
    
. "manual/en/function."
    
. strtr($int_funct[$i], "_", "-")
     .
".php";
    print
"    <td><a href=\"" . $doc
    
. "\" target=\"phpwin\">"
    
. $int_funct[$i]
     .
"</a></td>\n";
    if((
$i > 1)
     && ((
$i+$num_cols)%$num_cols==($num_cols-1)))  
      print
"   </tr>\n   <tr>\n";
    }
  for(
$i=($num_cols-($count%$num_cols));$i>0;$i--) 
    print
"    <td>&nbsp;</td>\n";
?>
  </table>
 </body>
</html>

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