Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Welcome to the TechnoWorldInc! Community!
Recent Updates
[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » PHP
 Functions to work with PHP Functions
Pages: [1]   Go Down
  Print  
Author Topic: Functions to work with PHP Functions  (Read 1067 times)
Daniel Franklin
TWI Hero
**********


Karma: 3
Offline Offline

Posts: 16647


View Profile Email
Functions to work with PHP Functions
« Posted: September 26, 2007, 10:18:52 AM »


full list of PHP functions you can visit Zend's PHP functions index .

Using these functions you can query the stats/status of your functions, these functions are very useful in dynamic application creation.


For example, using func_get_arg and func_num_args functions you can simulate the function overloading in PHP.

Read a good example for function overloading in PHP

Functions I am writing on this article are :-


get_defined_functions()
You want to how many functions are in your installation of PHP, just call this function, it will return an array of all php functions you can call. For the convince it return an multidimensional array, so you can access both internal and user defined functions separately.



func_get_arg()
Returns the argument which is at the arg_num'th offset into a user-defined function's argument list. Function arguments are counted starting from zero. func_get_arg() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
If arg_num is greater than the number of arguments actually passed, a warning will be generated and func_get_arg() will return FALSE.
As this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If you must pass this value, assign the results to a variable, and pass the variable.


func_get_args()

Returns an array in which each element is a copy of the corresponding member of the current user-defined function's argument list. func_get_args() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
This function returns a copy of the passed arguments only, and does not account for default (non-passed) arguments.
As this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If you must pass this value, assign the results to a variable, and pass the variable.


func_num_args() Returns the number of arguments passed into the current user-defined function. func_num_args() will generate a warning if called from outside of a user-defined function. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
As func_get_arg() this function also can not be passed as argument to another function.




function_exists()
Checks the list of defined functions, both built-in (internal) and user-defined, for function_name. Returns TRUE on success or FALSE on failure.



create_function()
Creates an anonymous function from the parameters passed, and returns a unique name for it. Usually the args will be passed as a single quote delimited string, and this is also recommended for the code. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.

This is one of very useful function to create dynamic application, using this function you can create the function at run time and then use them as per your requirements.


call_user_func()
Call a user defined function given by the function parameter.
People are divided on the use of this function, some thinks that it is not needed at all when we can run the function on the variable itself.
Like use of this function is
 function test($value) { print "This is $value"; }

call_user_func("test","test value");
some people prefer using variable function like this :-
 $funcname="test"; $funcname("test"); 

This is also a call_usr_func_array function.


is_callable()
If you are going to use a a variable function like previous example, you may need to verify if a function already present and callable? using this function you can do that.
This function Verify that the contents of a variable can be called as a function. This can check that a simple variable contains the name of a valid function, or that an array contains a properly encoded object and function name.
The var parameter can be either the name of a function stored in a string variable, or an object and the name of a method within the object, like this:
array($SomeObject, 'MethodName')

In some way it is similar to function_exisits function but it does more that that if you just want to check the syntax then you can pass a second argument as True, in that case it only verifies that var might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string.



So just start being familiar with functions to work with PHP functions, by doing so you can write good, effective and robust applications.

Articles Source - Free Articles

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.104 seconds with 24 queries.