Classes and Objects

The Basics class Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class. The class name can be any valid label which is a not a PHP reserved word. A valid class […]

Internal (built-in) functions

PHP comes standard with many functions and constructs. There are also functions that require specific PHP extensions compiled in, otherwise fatal «undefined function» errors will appear. For example, to use image functions such as imagecreatetruecolor(), PHP must be compiled with GD support. Or, to use mysql_connect(), PHP must be compiled with MySQL support. There are […]

Variable functions on PHP

PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so […]

Returning values

Values are returned by using the optional return statement. Any type may be returned, including arrays and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called. See return() for more information. Note: If the return() is omitted the value NULL will be […]

Function arguments

Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists are also supported, see also the function references for func_num_args(), func_get_arg(), and func_get_args() for more information. Example #1 Passing arrays […]

Example , Functions within functions

<?php function foo() { function bar() { echo «I don’t exist until foo() is called.\n»; } } /* We can’t call bar() yet since it doesn’t exist. */ foo(); /* Now we can call bar(), foo()’s processesing has made it accessible. */ bar(); ?>

example ,Conditional functions on PHP

<?php $makefoo = true; /* We can’t call foo() from here since it doesn’t exist yet, but we can call bar() */ bar(); if ($makefoo) { function foo() { echo «I don’t exist until program execution reaches me.\n»; } } /* Now we can safely call foo() since $makefoo evaluated to true */ if ($makefoo) […]

include function on PHP

The include() statement includes and evaluates the specified file. The documentation below also applies to require(). Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include() will finally check in the calling script’s own directory and the current working […]

require on PHP

require() is identical to include() except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue. See the include() documentation for how this works.