Professional Documents
Culture Documents
These include $_GET, $_POST, $_COOKIE, $_SESSION, $_SERVER, $_ENV, $_FILES and
$_REQUEST. Most of these are fairly self-explainatory. $_GET are the variables passed by forms with
a GET method or after the end of the path such as example.com/search.php?
GETARG1=GETVAL1&foo=bar. $_POST is any variable submitted by a form with method POST.
$_COOKIE is full of cookies setup by your PHP script. $_FILES is full of any uploaded files submitted
through a form with enctype multipart/data and method POST. $_SESSION are variables you
have set and committed to the session. $_ENV are environment settings from the operating system.
$_SERVER are variables set up by Apache. They’re all fairly self explainatory.
$_REQUEST seems sporadic. Sometimes it matches $_POST, sometimes $_GET, sometimes it seems
to pick and choose.
Its logic is fairly simple. Request is full of the “unsafe” variables. It will generally contain $_GET,
$_POST and $_COOKIE. This is configurable and is documented. In the beginning of execution,
$_REQUEST is a clone of $_GET. $_POST is then merged into the array, overwriting keys if they exist
in both $_GET and $_POST. Finally, $_COOKIE is merged into the array, again overwriting old
values.
?>
<form method='post'>
Question: <input type='text' name='question'/><br />
<input type='submit'>
</form>
Class
Constructor
In PHP 5 developers can declare constructor methods for classes. In this, those classes which have a
constructor method call this method for each newly created object.
Destructors
The destructor concept is introduced in PHP 5. This destructor concept is similar to other object
oriented languages. In this the destructor will be called as soon as all references to a particular object
have been removed or when the object has been explicitly destroyed.
Abstract Class - In the simplest sense, an abstract class is a class that cannot (and should not) be
instantiated. Abstract class shouldn’t provide any explicit definition for its methods or properties. These
methods and properties should be specifically defined within the subclasses, which automatically
would inherit them from the base class.
Magic Methods
The function names _construct, _sleep, _wakeup, _tostring are all magical methods in PHP. There
cannot be any functions with these names in the classes. These functions can be had only if we want the
magical functionality associated with them.
_sleep
The _sleep magic method is used to close any database connections that the object may have. It is also
used to commit pending data and perform similar cleanup tasks. It is also used if there are very large
objects which do not have to be saved completely.
_wakeup
The _wakeup magic method is used to reconstruct any resources that the object may have. The basic
function of _wakeup is to reestablish any database connections that may have been lost during
serialization and perform other initialization tasks.
_tostring
The _tostring magic method allows a class to decide that how it will react when it is converted to
string.
Abstract
A new concept of abstract classes and methods has been introduced in PHP5. When a class is defined
as abstract then it is not allowed to create the instance of that class. A class that contains at least one
abstract method must also be abstract. The methods defined as abstract cannot define the
implementation; they just declare the method’s signature.
When a child class is inheriting from an abstract parent class, then all the methods marked abstract in
parent class declaration must also be additionally defined by the child class. These methods must be
defined with the same or weaker access. This means that if an abstract method is declared as protected
in the parent class then it must be declared either as protected or public in the child class.
Static Keyword
When class members or methods are declared as static then there is no need to instantiate that class.
These members and methods are accessible without the instantiation of the class. If a member is
declared as static then it cannot be accessed by an instantiated class object, but a method declared as
static can be accessed by an instantiated class object.
The static declaration of a class must be after the visibility declaration (means that after the member or
method has been declared as public, protected, or private).
The static method calls are resolved at compile time and static properties cannot be accessed through
the object through the arrow operator (->).
Interfaces
Object interfaces allow the creation of a code which specifies that which method a class must
implement, without having to define how these methods have to be handled.
Interfaces are defined in the same way as a class is defined. These interfaces are defined with the
keyword “interface”. In the interface the contents of the methods do not have to be defined and all the
methods declared in the interface must be declared as public.
Implementation of Interfaces
To implement an interface, the implements operator is used. The methods must be defined before
implementation and all the methods in the interface must be implemented within a class.
Exceptions
Exception handling in PHP is similar to that of other programming languages. Within a PHP block of
code we can throw, try and catch an exception. There must be at least one catch block in a try block. In
this multiple catch blocks can be used to catch different class types. In exception handling the
execution will continue after the last catch block has been encountered and exceptions can be thrown
within catch blocks.
In exception handling when an exception is thrown, the code following the statement will not be
executed rather PHP will attempt to find the first matching catch block. If the exception is not caught
then it will result in a fatal error with an uncaught exception message.
ob_start
This function will turn output buffering on. While output buffering is active no output is sent from the
script (other than headers), instead the output is stored in an internal buffer.
The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To
output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will
silently discard the buffer contents.
Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just
make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback
functions are active, output is being filtered sequentially through each of them in nesting order.
Depending how large the table is this may take a few milliseconds to a number of minutes to run.
As many additional columns can be added to the list as required. Again, this may only take a few
milliseconds to many minutes depending on the size of the data in the table.
To detect the operating system on the client machine, your script should analyze the
navigator.appVersion string. Below is a simple example of a script that sets the variable
OSName to reflect the actual client OS.
// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS