What Is New in PHP 7.0
| Category | Key Changes |
|---|---|
| Performance | PHPNG engine (Zend Engine 3), up to 2x performance improvement |
| New Features | Scalar type declarations, Return type declarations, Spaceship operator, Null coalescing operator |
| Syntax | Anonymous classes, Unicode codepoint escape syntax, Group use declarations |
| Security | Filtered unserialize(), CSPRNG functions, Removal of insecure library dependencies |
| Deprecated | PHP4-style constructors, Multiple default clauses in switch statements |
| Removed | mysql extension, ASP-style tags, ereg extension |
What performance improvements does PHP 7.0 offer?
The biggest change is the new PHPNG engine (Zend Engine 3), which delivers significantly reduced memory consumption and up to twice the performance of PHP 5.6. This was achieved through a comprehensive refactoring of internal data structures. In practice, this means your applications run faster and can handle more traffic on the same hardware.
What new language features were introduced?
Scalar and Return Type Declarations
You can now enforce parameter and return value types. This makes code more predictable and self-documenting.
function sum(int $a, int $b): int {
return $a + $b;
}
Null Coalescing Operator
The ?? operator provides a shortcut for common isset() checks. It returns the first operand if it exists and is not NULL, otherwise the second operand.
$username = $_GET['user'] ?? 'nobody';
Spaceship Operator
The <=> operator is used for combined comparison. It returns -1, 0, or 1 when $a is respectively less than, equal to, or greater than $b.
echo 5 <=> 8; // -1
Anonymous Classes
You can now instantiate objects from unnamed classes, similar to anonymous functions. This is useful for one-off implementations.
$util->setLogger(new class {
public function log($msg) {
echo $msg;
}
});
What security enhancements were made?
The unserialize() function was hardened with an optional whitelist of allowed classes, reducing the risk of object injection attacks. New Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) functions were added: random_bytes() and random_int(). These are the preferred methods for generating secure random values.
What was removed or deprecated?
The old mysql_* functions were completely removed--you must use mysqli or PDO instead. ASP-style tags (<% %>) and script tags (<script language="php">) were also removed. PHP4-style constructors (methods with the same name as the class) are now deprecated and will generate an E_DEPRECATED error.
FAQ
Is PHP 7.0 really twice as fast?
Yes, for many real-world applications, especially those using popular frameworks, the performance improvement is very noticeable. The reduced memory footprint is often just as beneficial.
Why should I use the new null coalescing operator?
It dramatically cleans up verbose isset() checks. Instead of writing $a = isset($b) ? $b : $c;, you can simply write $a = $b ?? $c;.
My code uses the old mysql extension. What do I do?
You must migrate to either MySQLi or PDO_MySQL before upgrading. This is a breaking change and the most common upgrade hurdle from PHP 5.x.
What are the new CSPRNG functions for?
Use random_int() for generating cryptographically secure integers and random_bytes() for generating secure random strings. They replace older functions like rand() and openssl_random_pseudo_bytes() for security-critical tasks.
Are typed returns enforced strictly?
It depends on the declared strict mode. By default, PHP will attempt to coerce types. You can enable strict mode by declaring declare(strict_types=1); at the top of your file, which will cause type mismatches to throw a TypeError.