New in php 5.6

PHP 5.6 have lots of new improvements but also marked some functions as deprecated ,Let’s discuss below Backward Incompatible .

Backward Incompatible

json_decode

json_decode() function now removes all non-lowercase variants of json literals ex: true, false, and null.

GMP Resources

If you are checking resource explicit using is_resource() then you have to modify your  otherwise no need to modify anything.

Mcrypt

Some Mcrypt function like mcrypt_encrypt(), mcrypt_decrypt(), mcrypt_cbc(), mcrypt_cfb(), mcrypt_ecb(), mcrypt_generic(), and mcrypt_ofb() now will not accept keys if size is incorrect .

Array Values and Overwriting

Previously in it’s¬†version array value use to overwritten when the explicit key was the same as sequential implicit key. let’s consider below example

class fruits {
        const ONE = 1;
         
        public $array = [
            self::ONE => 'apple',
            'mango',
            'guava',
        ];
    }
     
    $data = new fruits();
     
    print_r($data);
     
    // Before 5.6
    array('mango', 'gauva')
     
    // PHP 5.6
    array('apple', 'mango', 'gauva') 

 

What’s new in PHP 5.6

Constant Scalar Expressions

Now it’s possible to have scalar expression that holds both numeric and string literals.

const ONE = 1;
// Scalar Expression in constant
const TWO = ONE * 2;
 
class sample {
    // Scalar Expression in Property    
    const THREE = TWO + 1;
     
    // Scalar Expression in Methods
    public hello f($a = ONE + self::THREE) {
        return $a;
    }
}
 
echo (new sample)->hello()."\n";

Argument Unpacking

get arguments of array or a set of Traversable objects.

function sample($name, $fruit1, $fruit2, $fruit3) {
        echo "Name:". $name.'
';
        echo "fruit1:", $fruit1.'
';
        echo "fruit2:", $fruit2.'
';
        echo "fruit3:", $fruit3;
    }
     
    $sample = ['apple', 'mango', 'gauva'];
    sample('Unitedwebsoft', ...$sample);
    // Output:
    // Name: Unitedwebsoft
    // fruit: apple
    // fruit1: mango
    // fruit1: gauva

** shorthand

now it’s easy in 5.5 to declare exponentiation as shorthand ,let’s check below

echo 3 ** 3;
echo "
";
$a=3;
$a **= 3;
echo $a;
 
// Output
// 27
// 27

phpdbg

User interactive debugger included in PHP5.6 .for details of phpdbg check official documentation .

Default Character Encoding

Using this function default_charset() ,we can now define default chracter of these functions htmlentities(), html_entity_decode() and htmlspecialchars().

Large File Upload

Now it is possible to uploaded larger file than 2 GB .

Online Web Development Training,Video Tutorials