Promo Offers XMAS Offers:
KVM VPS @ UP TO 50% OFF for 3 mos. Learn More Dedicated @ UP TO 56% OFF for 1 mo. Learn More
  • Your Cart is Empty
  • Cart
  • Log In

PHP5 - version overview

PHP is a computer programming language originally designed for producing dynamic web pages. The name PHP means PHP Hypertext Preprocessor.

PHP 5

PHP 5 was released 4 years after the introduction of PHP 4 to the Internet scene, aimed to bring a brand new functionality to the PHP language. The PHP team focused on what was missing or not well supported in the older versions. The 5th revision is focused on 3 major areas: Object-Oriented programming, XML and MySQL support.

Object-Oriented programming

While this feature was present in PHP 4, PHP 5 presents a completely reworked object model, which now offers:

  • Constructors
  • Destructors
  • Public, protected, and private properties and methods
  • Interfaces
  • Abstract classes
  • Class type hints
  • Static properties and methods
  • Final properties and methods
  • Magical methods

In PHP 5 programmers can also pass objects by reference and not just by value.

All objects are now passed by reference:

<?php
$header = new Content();
$header->text = 'My header text here';

$footer = $header;
$footer->text = 'My footer text here';

echo $header->text;
// Will be 'My header text here' in PHP4
// Will be 'My footer text here' in PHP5
?>

Reworked MySQL extension

PHP 5 comes with a completely reworked MySQL extension to provide support for the newest version of MySQL, now labeled MySQLi, which stands for MySQL improved. The new extension offers:

  • Prepared statements
  • Bound input and output parameters
  • SSL connections
  • Multi-query functions
  • MySQL can now use PHP's new OO model

Reworked XML extension

In PHP4, XML tools did the job, but were not really designed to work together and often patches were required to achieve the needed functionality. PHP5 brings a reworked XML parser, with tools, able to work with one another. The new XML extensions:

  • Can work together as a whole.
  • Are included in just a single XML library: libxml2.
  • Fully comply with W3 specifications.
  • Provide efficient data processing
  • Can provide you with the exact XML tool for the task at hand.

PHP5 also introduces the SimpleXML extension, which allows you to easily handle the data in XML documents, treating it as an array and looping through it.

Exception handling

Exceptions are very popular in other Object-Oriented languages, such as Python and Java, and were completely missing in PHP 4. With PHP 5, exception handling is now present in the PHP core, allowing for a separation of the programming logic and the error handling. The coder can now place them in adjoining blocs for easier referencing.

Exception handling:

<?php
try {
    $cache->write();
} catch (AccessDeniedException $e) {
    die('Could not write the cache, access denied.');
} catch (Exception $e) {
    die('An unknown error occurred: '.$e->getMessage());
}
?>

Standard PHP Library and Iterators

PHP 5 is the first version to have iterators in the PHP core. Iterators allow the coder to use a for-each loop through various data, such as XML files and database results. In the Standard PHP Library the coders can find a collection of iterators, through which the results of the loop can be filtered or modified.

Directory iteration in PHP 4:

$dir = opendir($path);
while (false !== ($file = readdir($dir))) {
print "$file\n";
}
closedir($dir);

Directory iteration with the new DirectoryIterator:

foreach (new DirectoryIterator($path) as $file) {
print "$file\n";
}

PHP 5 with NTC Hosting

All web hosting plans offered by NTC Hosting support PHP5. Our Web Hosting Control Panel comes equipped with a convenient tool, which will allow you to choose between PHP4 and PHP5 and will provide you with all the tools needed to create your unique website. We have also prepared a detailed comparison between the available PHP versions to help you choose the right one.