Some PHP functions you must know
PHP is a widely-used general-purpose scripting language that is
especially suited for Web development and can be embedded into HTML.
PHP has more than several thousands functions for many purpose.
For writing a program in any language we need basic language construct,
syntax and a large number of functions to get the desired result from
In this article I will write about the some functions of PHP which are
very useful in creating a bug free, clean and efficient program.
We used print and echo functions to send the output to browser. so they
are of course one of the necessary functions of PHP. Without using them
you can not write a PHP program or at least can not show your work to
You must know the functions describe in this article, in order to write
a good and bug free code.
These are :-
The error_reporting() function sets the error_reporting directive at
runtime. PHP has many levels of errors, using this function sets that
level for the duration (runtime) of your script.
This function determine whether a variable is set or not. It is very
useful in avoiding Notices generated by setting your error_reporting to
E_ALL. Undefined or un-initialised variables may be the main reasons
for many irritating bugs in your program, but remember isset() only
works with variables as passing anything else will result in a parse
error. For checking if constants are set use the defined() function.
This function prints human-readable information about a variable
It displays information about a variable in a way that's readable by
humans. If given a string, integer or float, the value itself will be
printed. If given an array, values will be presented in a format that
shows keys and elements. Similar notation is used for objects.
This function displays structured information about one or more
expressions that includes its type and value. Arrays and objects are
explored recursively with values indented to show structure. In some
ways print_r and var_dump are similar.
ini_set and ini_get
These functions sets and gets the value of the given configuration
option. Returns the old value on success, FALSE on failure. The
configuration option will keep this new value during the script's
execution, and will be restored at the script's ending.
Not all the available options can be changed using ini_set(), You can
consult the PHP manual for a full list of available variables.
This function set the number of seconds a script is allowed to run. If
this is reached, the script returns a fatal error. The default limit is
30 seconds or, if it exists, the max_execution_time value defined in the
php.ini. If seconds is set to zero, no time limit is imposed. It is very
usefull if you are working with a script which may take some time to
finish like sending a large number of emails.
When called, set_time_limit() restarts the timeout counter from zero. In
other words, if the timeout is the default 30 seconds, and 25 seconds
into script execution a call such as set_time_limit(20) is made, the
script will run for a total of 45 seconds before timing out.
set_time_limit() has no effect when PHP is running in safe mode. There
is no workaround other than turning off safe mode or changing the time
limit in the php.ini.
As I have told you , using these functions you can write a good and
bug free code so keep using them
About the Author
Zareef Ahmed is php developer based in india, Delhi. He is doing web development since last five-six years.
He can be contacted at email@example.com. To know more about him you can visit his home page at http://www.zareef.net
Written by: Zareef Ahmed