PHP 7 new features list

Today google about new enhancement and featured introduced in PHP 7 and found that PHP 7 is really having a lot of new functions and features with it. Here I am listing few of them which i found interesting.

1)The removal of ASP tags (<%) and script tags (<script language=php>) as a means of entering or leaving PHP mode. (https://wiki.php.net/rfc/remove_alternative_php_tags)

The following syntactical elements are removed:
  • <% opening tag
  • <%= opening tag with echo
  • %> closing tag
  • (<script\s+language\s*=\s*(php|"php"|'php')\s*>)i opening tag
  • (</script>)i closing tag
2) Remove deprecated functionality in PHP 7 (https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts) The following extensions are deprecated and will be removed in PHP 7.
  • ext/ereg (since PHP 5.3;)
  • ext/mysql (since PHP 5.5; use ext/mysqli or ext/pdo_mysql instead)
3) Remove PHP 4 Constructors : (https://wiki.php.net/rfc/remove_php4_constructors) PHP 7 will emit E_DEPRECATED whenever a PHP 4 constructor is defined. When the method name matches the class name, the class is not in a namespace, and a PHP 5 constructor (__construct) is not present then an E_DEPRECATED will be emitted. PHP 8 will stop emitting E_DEPRECATED and the methods will not be recognized as constructors. 4) Multiple default is now disallowed in switch statement. (https://wiki.php.net/rfc/switch.default.multiple) 5) Combined Comparison (Spaceship) Operator: (https://wiki.php.net/rfc/combined-comparison-operator) Add a new operator (expr) <=> (expr), it returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater.
// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
6) Null Coalesce Operator (https://wiki.php.net/rfc/isset_ternary) The coalesce, or ??, operator is added, which returns the result of its first operand if it exists and is not NULL, or else its second operand. This means the $_GET['mykey'] ?? "" is completely safe and will not raise an E_NOTICE. Some examples of its use:
$username = $_GET['user'] ?? 'nobody';
// equivalent to: $username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
7) Anonymous Classes (https://wiki.php.net/rfc/anonymous_classes) An anonymous class is a class without a (programmer declared) name. The functionality of the object is no different from that of an object of a named class. They use the existing class syntax, with the name missing:
/* return an anonymous implementation of a Page for your MVC framework */
return new class($controller) implements Page {
    public function __construct($controller) {
        /* ... */
    }
    /* ... */
};
8) Scalar Type Declarations (https://wiki.php.net/rfc/scalar_type_hints_v5) No new reserved words are added. The names int, float, string and bool are recognised and allowed as type declarations, and prohibited from use as class/interface/trait names (including with use and class_alias).
function add(int $a, int $b)
{
    return $a + $b;
}

if(add(5.5, 5) === 10) {
    echo "Next step !";
}
9) Return Type Declarations (https://wiki.php.net/rfc/return_types) An optional return type declaration to function declarations including closures, functions, generators, and methods.Code which does not declare a return type will continue to work exactly as it currently does.
// Int is not a valid type declaration
 
function answer(): int {
    return 42;
}
answer();
Some usefulll links which will tell you more about PHP 7 1) https://wiki.php.net/rfc 2) http://php7-tutorial.com/#1 [si-contact-form form='1']



Your feedbacks are most welcome..