article directory
 

Differences Between PHP 4 and 5 - By: luudanh123

Language Features
  • PHP 5 allows limited type hinting. This allows you to specify that the param-
    eter to a function or class method can only be of a speciļ¬Āc class (or one of its
    subclasses), or an array. However, youmay not specify any other scalar types.
    The foreach construct now supports by-reference declaration of the value ele-
    ment.

  • A number of newfunctions, particularly for string and arraymanipulation, has
    also been added to the core platform.

Objects
  • For all intents and purposes, all objects in PHP 5 are passed by reference. This
    means that assigning an object to a variable will not create a copy of the for-
    mer, but simply creates another reference to it.

  • Constants, aswell as staticmethods and properties, can nowbe deļ¬Ānedwithin
    the scope of a class.

  • Class methods and properties now feature visibility, and can be declared as
    public, private or protected. Classes and methods can also be declared as
    final to prevent further inheritance.

  • Since all objects are assigned by reference, you now need a specializedmecha-
    nismto copy objects. This is provided by the clone construct and the __clone()
    magicmethod.

  • PHP 5 features uniļ¬Āed constructors and destructors-all constructors should
    now be named __construct(), and the new __destruct() magic method has
    been added for object destruction.

  • With the addition of interfaces and abstract classes, PHP developers now have
    far greater control over how they implement their object-oriented code. In-
    terfaces can be used to deļ¬Āne common APIs, while abstract classes provide
    models for class implementations that follow a speciļ¬Āc blueprint.

  • Class deļ¬Ānitions can now be loaded on demand by using the __autoload()
    function.

MagicMethods
Amultitude of new "magic"methods has been introduced in PHP 5:
  • __get() and __set() are called when accessing or assigning an undeļ¬Āned ob-
    ject property, while __call() is executed when calling a non-existent method
    of a class.

  • __isset() is called when passing an undeļ¬Āned property to the isset() con-
    struct.

  • __unset() is called when passing an undeļ¬Āned property to unset().

  • __toString() is called when trying to directly echo or print() an object.

  • __set_state() is inserted dynamically by var_export() to allow for re-
    initialization on execution of var_export()'s output.

Selected New Extensions

  • SimpleXML allows easy access to XML data using object and array notation.

  • PHP 5 also introduces a DOMXML, DOMXSL and Sablotron replacement in
    the formof the libxml2-based DOMand XSL extensions.

  • The PHP Data Objects (PDO) extension provides a uniļ¬Āed database access ex-
    tension that allows access to many different types of database systems by us-
    ing a common interface. PDO is not an abstraction layer-except for prepared
    queries, it does nothing to abstract the actual database code (SQL), itself.

  • The hash extension is a newreplacement for theGPLed libmhash; itwas added
    to the PHP core starting with version 5.1.2. It can produce hashes using many
    algorithms, including the familiarMD5 and SHA1, aswell as somemore secure
    (albeit slower) algorithms, such as snefru.

  • The Standard PHP Library (SPL) provides numerous interfaces that enhance
    the way classes interact with the PHP language, including the new Iterator
    interfaces.

  • The new Reļ¬'ection extension allows for runtime introspection of executing
    PHP code.

ErrorManagement
  • Classes now support exceptions; the new set_exception_handler() function
    allows you to deļ¬Āne a script-wide exception handler.

  • The E_STRICT error reporting level has been added to the language to emit no-
    tices when legacy or deprecated code is encountered

About the Author

Luu Danh, MyWayE, Ltd, has more than 5 years of experience in technology writing and web site development. you can also check out his latest website on Fun Girls Games or view Pregnancy FAQ. Thank you.

Article Directory Source: http://www.articlerich.com/profile/luudanh123/132169




Click the XML Icon Above to Receive Articles Via RSS!

Page copy protected against web site content infringement by Copyscape

Do not copy content from the page unless you comply with our terms of service.
Plagiarism will be detected by Copyscape.