Popular Post

Posted by : Unknown Sunday 22 September 2013

PHP 5
                                 


1) Generators are now available

    Generators provide a simple way to iterate through data without having to write a class  implementing the Iterator interface.

    Just like any other function a generator is defined with the function keyword, but unlike a normal function that just returns a result once, a generator can send back as many results as needed using the yield keyword.

    A simple example of using a generator function to print out a positive sequence of integers is shown
below.

    function xrange($start, $end, $step = 1)
     {

        for ($i = $start; $i <= $end; $i +=

$step)
        {
   
            yield $i;

        }

    }

    echo 'Single digit odd numbers: ';

    foreach (xrange(1, 9, 2) as $number)
    {

        echo "$number ";

    }

    echo "\n";

    This would print "Single digit odd

numbers:1,3,5,7,9".

2) Finally keyword added

    The addition of the "finally" keyword refines the way that PHP deals with exception handling.

    Like other high level languages PHP allows you to wrap code in a try and catch block. Any exception that is thrown by code within the try block will be passed     to code within the catch block to be handled.

    The finally keyword allows you to define a block of code, to be placed after the catch block, that will always be executed after the try and catch blocks,     regardless of whether an exception was thrown.

    The PHP manual gives this example:

    function inverse($x)
    {

            if (!$x)
        {

                    throw new Exception('Division by zero.');
            }

            return 1/$x;

    }

    try
    {
            echo inverse(5) . "\n";

    }
    catch (Exception $e)
    {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
    finally
    {

            echo "First finally.\n";

    }

3)New password hashing API

    The new password hashing API allows you to use one line of code to generate a salted password hash using bcrypt. For example:

    $hash = password_hash($password, PASSWORD_DEFAULT);

    password_hash() takes two arguments here, first the password as a string and second a constant setting the encryption algorithm to use.

    The password will be automatically salted and can be verified using the following code:

     password_verify($password, $hash);

    The current default encryption algorithm used is bcrypt, although this is expected to change as new and stronger algorithms are added to PHP.

    It is recommended to store the result in a database column that can expand beyond 60 characters.


4)New features added to GD library

    PHP's GD extension for creating and manipulating images has gained new capabilities.

    These include flipping support using the new imageflip() function, advanced cropping support using the imagecrop()

    and imagecropauto() functions, and WebP read and write support using the imagecreatefromwebp() and imagewebp() functions.

 





{ 1 comments... read them below or add one }

- Copyright © HD Wallpaper - Date A Live - Powered by Blogger - Designed by Johanes Djogan -