PHP Options&InformationPHP Options/InfoassertChecks if assertion is &false;Descriptionintassertstring|boolassertionassert will check the given
assertion and take appropriate action if
its result is &false;.
If the assertion is given as a string it
will be evaluated as PHP code by assert.
The advantages of a string assertion are
less overhead when assertion checking is off and messages
containing the assertion expression when
an assertion fails.
Assertions should be used as a debugging feature only. You may
use them for sanity-checks that test for conditions that should
always be &true; and that indicate some programming errors if not
or to check for the presence of certain features like extension
functions or certain system limits and features.
Assertions should not be used for normal runtime operations like
input parameter checks. As a rule of thumb your code should
always be able to work correctly if assertion checking is not
activated.
The behavior of assert may be configured by
assert_options or by .ini-settings described
in that functions manual page.
The assert_options function and/or
ASSERT_CALLBACK configuration directive allow a callback function
to be set to handle failed assertions.
assert callbacks are particularly useful for
building automated test suites because they allow you to easily
capture the code passed to the assertion, along with information
on where the assertion was made. While this information can be
captured via other methods, using assertions makes it much faster
and easier!
The callback function should accept three arguments. The first
argument will contain the file the assertion failed in. The
second argument will contain the line the assertion failed on and
the third argument will contain the expression that failed (if
any - literal values such as 1 or "two" will not be passed via
this argument)
Handle a failed assertion with a custom handler
Assertion Failed:
File '$file'
Line '$line'
Code '$code' ";
}
// Set up the callback
assert_options (ASSERT_CALLBACK, 'my_assert_handler');
// Make an assertion that should fail
assert ('mysql_query ("")');
?>
]]>
assert_optionsSet/get the various assert flagsDescriptionmixedassert_optionsintwhatmixedvalue
Using assert_options you may set the various
assert control options or just query their
current settings.
Assert Optionsoptionini-parameterdefaultdescriptionASSERT_ACTIVEassert.active1enable assert evaluationASSERT_WARNINGassert.warning1issue a PHP warning for each failed assertionASSERT_BAILassert.bail0terminate execution on failed assertionsASSERT_QUIET_EVALassert.quiet_eval0
disable error_reporting during assertion expression
evaluation
ASSERT_CALLBACKassert_callback(&null;)user function to call on failed assertions
assert_options will return the original
setting of any option or &false; on errors.
extension_loadedFind out whether an extension is loadedDescriptionboolextension_loadedstringname
Returns &true; if the extension identified by
name is loaded. You can see the names of
various extensions by using phpinfo.
See also phpinfo.
This function was added in 3.0.10.
dlLoads a PHP extension at runtimeDescriptionintdlstringlibrary
Loads the PHP extension defined in
library. See also the Extension Loading Directives
getenvGets the value of an environment variableDescriptionstringgetenvstringvarname
Returns the value of the environment variable
varname, or &false; on an error.
You can see a list of all the environmental variables by using
phpinfo. You can find out what many of them
mean by taking a look at the CGI
specification, specifically the page on environmental variables.
This function does not work in ISAPI mode.
See also putenv.
get_cfg_var
Gets the value of a PHP configuration option
Descriptionstringget_cfg_varstringvarname
Returns the current value of the PHP configuration variable
specified by varname, or &false; if an
error occurs.
It will not return configuration information set when the PHP was
compiled, or read from an Apache configuration file (using the
php3_configuration_option directives).
To check whether the system is using a configuration file, try
retrieving the value of the cfg_file_path configuration
setting. If this is available, a configuration file is being
used.
See also ini_get.
get_current_user
Gets the name of the owner of the current PHP script
Descriptionstringget_current_user
Returns the name of the owner of the current PHP script.
See also getmyuid,
getmygid, getmypid,
getmyinode, and
getlastmod.
get_defined_constants
Returns an associative array with the names of all the constants
and their values
Descriptionarrayget_defined_constants
This function returns the names and values of all the constants
currently defined. This includes those created by extensions as
well as those created with the define
function.
For example the line below
will print a list like:
1
[E_WARNING] => 2
[E_PARSE] => 4
[E_NOTICE] => 8
[E_CORE_ERROR] => 16
[E_CORE_WARNING] => 32
[E_COMPILE_ERROR] => 64
[E_COMPILE_WARNING] => 128
[E_USER_ERROR] => 256
[E_USER_WARNING] => 512
[E_USER_NOTICE] => 1024
[E_ALL] => 2047
[TRUE] => 1
)
]]>
See also get_loaded_extensions,
get_defined_functions and
get_defined_vars.
get_extension_funcs
Returns an array with the names of the functions of a module
Descriptionarrayget_extension_funcsstringmodule_name
This function returns the names of all the functions defined in
the module indicated by module_name.
For example the lines below
will print a list of the functions in the modules
xml and gd respectively.
See also: get_loaded_extensionsgetmygidGet PHP script owner's GIDDescriptionintgetmygid
Returns the group ID of the current script, or &false; on error.
See also getmyuid,
getmypid,
get_current_user,
getmyinode, and
getlastmod.
get_included_files
Returns an array with the names of included or required files
Descriptionarrayget_included_files
Returns an array of the names of all files that have been
included using include,
include_once, require
or require_once.
Files that are included or required multiple times only show up
once in the returned array.
Files included using the auto_prepend_file
configuration directive are not included in the returned array.
get_included_files Example
]]>
will generate the following output:
In PHP 4.0.1pl2 and previous versions
get_included_files assumed that the
required files ended in the extension .php;
other extensions would not be returned. The array returned by
get_included_files was an associative array
and only listed files included by include
and include_once.
See also: include,
include_once, require,
require_once, and
get_required_files.
get_loaded_extensions
Returns an array with the names of all modules compiled and
loaded
Descriptionarrayget_loaded_extensions
This function returns the names of all the modules compiled and
loaded in the PHP interpreter.
For example the line below
will print a list like:
xml
[1] => wddx
[2] => standard
[3] => session
[4] => posix
[5] => pgsql
[6] => pcre
[7] => gd
[8] => ftp
[9] => db
[10] => Calendar
[11] => bcmath
)
]]>
See also: get_extension_funcs.
get_magic_quotes_gpc
Gets the current active configuration setting of magic quotes gpc
Descriptionlongget_magic_quotes_gpc
Returns the current active configuration setting of magic_quotes_gpc (0 for
off, 1 for on).
See also get_magic_quotes_runtime and
set_magic_quotes_runtime.
get_magic_quotes_runtime
Gets the current active configuration setting of
magic_quotes_runtime
Descriptionlongget_magic_quotes_runtime
Returns the current active configuration setting of magic_quotes_runtime
(0 for off, 1 for on).
See also get_magic_quotes_gpc and
set_magic_quotes_runtime.
getlastmodGets time of last page modificationDescriptionintgetlastmod
Returns the time of the last modification of the current
page. The value returned is a Unix timestamp, suitable for
feeding to date. Returns &false; on error.
getlastmod() example
See also date,
getmyuid, getmygid,
get_current_user,
getmyinode, and
getmypid.
getmyinodeGets the inode of the current scriptDescriptionintgetmyinode
Returns the current script's inode, or &false; on error.
See also getmygid,
getmyuid,
get_current_user,
getmypid, and
getlastmod.
¬e.no-windows;
getmypidGets PHP's process IDDescriptionintgetmypid
Returns the current PHP process ID, or &false; on error.
Process IDs are not unique, thus they are a weak entropy
source. We recommend against relying on pids in
security-dependent contexts.
See also getmygid,
getmyuid,
get_current_user,
getmyinode, and
getlastmod.
getmyuidGets PHP script owner's UIDDescriptionintgetmyuid
Returns the user ID of the current script, or &false; on error.
See also getmygid,
getmypid,
get_current_user,
getmyinode, and
getlastmod.
get_required_files
Returns an array with the names of included or required files
Descriptionarrayget_required_files
As of PHP 4.0.4, this function is an alias for
get_included_files
In PHP 4.0.1pl2 and previous versions
get_required_files assumed that the required
files ended in the extension .php, other
extensions would not be returned. The array returned by
get_required_files was an associative array
and only listed files included by require
and require_once.
See also: require,
require_once, include,
include_once, and
get_included_files.
getrusageGets the current resource usagesDescriptionarraygetrusageintwho
This is an interface to getrusage(2). It returns an associative
array containing the data returned from the system call. If who
is 1, getrusage will be called with RUSAGE_CHILDREN.
All entries are accessible by using their documented field names.
Getrusage Example
See your system's man page on getrusage(2) for more details.
ini_alter
Changes the value of a configuration option
Descriptionstringini_alterstringvarnamestringnewvalue
Changes the value of a configuration option, returns &false; on
failure, and the previous value of the configuration option on
success.
This is an alias of ini_set
See also ini_get,
ini_get_all,
ini_restore, and
ini_setini_getGets the value of a configuration optionDescriptionstringini_getstringvarname
Returns the value of the configuration option on success, an
empty string on failure.
See also get_cfg_var,
ini_get_all,
ini_alter,
ini_restore, and
ini_setini_get_allGets all configuration optionsDescriptionarrayini_get_allstringextension
Returns all the registered configuration options as an
associative array. If optional extension
parameter is set, returns only options specific for that
extension.
See also: ini_alter,
ini_restore, ini_get,
and ini_setini_restoreRestores the value of a configuration optionDescriptionstringini_restorestringvarname
Restores a given configuration option to its original value.
See also: ini_alter,
ini_get, ini_get_all,
and ini_setini_setSets the value of a configuration optionDescriptionstringini_setstringvarnamestringnewvalue
Sets 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. Below is a table with a list of all
PHP options (as of PHP 4.0.5-dev), indicating which ones can be
changed/set and at what level.
Definition of PHP_INI_* constantsConstantValueMeaningPHP_INI_USER1Entry can be set in user scriptsPHP_INI_PERDIR2
Entry can be set in .htaccessPHP_INI_SYSTEM4
Entry can be set in php.ini or
httpd.confPHP_INI_ALL7Entry can be set anywhere
See also: ini_alter,
ini_get, and
ini_restorephpcreditsPrints out the credits for PHPDescriptionvoidphpcreditsintflag
This function prints out the credits listing the PHP developers,
modules, etc. It generates the appropriate HTML codes to insert
the information in a page. A parameter indicating what will be
printed (a pre-defined constant flag, see table below) needs to
be passed. For example to print the general credits, you will use
somewhere in your code:
And if you want to print the core developers and the
documentation group, in a page of its own, you will use:
]]>
And if you feel like embedding all the credits in your page, then
code like the one below will do it:
My credits page