PHP 7 new features list

Posted on October 19, 2015 by Suresh Kamrushi in PHP

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. (

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 (
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 : (
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. (

5) Combined Comparison (Spaceship) 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 (
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 (
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 (
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 (
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;

Some usefulll links which will tell you more about PHP 7

Tagged as ,