Software Technology Web Development

PHP 7 – what’s new and feature spotlight

You might already know that PHP 7 is now a stable release. PHP 7 is a new major version, still it has very few backward incompatible changes. However, lots of functions have been deprecated. This is the most important version update for PHP since the release of PHP 5 in the year of 2004. Drastic performance improvements along with reduced memory consumption will supercharge your web application. The new Zend Engine 3.0 enables your website with 2x faster performance and 50% better memory consumption than PHP 5.6 which allows you to serve more concurrent visitors without adding a new hardware. PHP 7 is based on the PHPNG AKA PHP Next-Gen project, that was led by Zend. Also, PHP 7 now has support for 64-bit Windows system which was lacking in 5.x version. However, it was already supported in the Linux 64-bit platforms and local LAMP stacks. Besides the performance enhancements, PHP 7 has introduced many new features, like new operators, type declarations, anonymous classes, namespace imports, etc.

It’s PHP 7 after PHP 5.6 – Why the version jump?

The last stable release of PHP before the version 7 was the version 5.6! Actually, PHP 6 was in the development phase in the past as an experimental project, but it never entered into the production phase. The PHP development team decided to drop the version 6 after some voting system.

PHP 7 Zend Infographic
PHP 7 Infographic, Graphic Curtesy: –

New Operators

null coalescing operator ( ?? )

This new operator has been added to simplify the inline if/else syntax with the ternary operator. So rather than writing this

$var = !empty($_POST['some_var']) ? $_POST['some_var'] : 0;
Now you can write this
$var = $_POST['some_var'] ?? 0;
This can be chained as well
$var = $_POST['some_var'] ?? $_POST['another_var'] ?? 0;

spaceship operator ( <=> )

This is another new operator added in PHP 7. It compares two expressions and returns -1, 0, or 1 respectively for less than, equals, or greater than for the match.

// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
// Floats
echo 1.5 <=> 1.5; // 0
echo 1.5 <=> 2.5; // -1
echo 2.5 <=> 1.5; // 1
// Strings
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1

New classes and interfaces

There are a couple of new classes and interfaces introduced. Especially the error handling part. The Exception Hierarchy classes are as below which are very useful.

  • Throwable
  • Error
  • TypeError
  • ParseError
  • AssertionError
  • ArithmeticError
  • DivisionByZeroError

New functions

There are a couple of new functions introduced in PHP 7 version.

ClosureClosure::call() to bind and call the closure function.
Mathintdiv() function for integer division. This is a very handy function.
Error Handlingerror_clear_last() to clear the most recent error.
Resourcesget_resources() to get the list of the resources created by type.
Zlib Compression – inflate_add(), deflate_add(), inflate_init(), deflate_init()

Modified functions

Some existing functions are modified. Like –
dirname() – now optionally takes a second parameter, depth, to get the name of the directory depth levels up from the current directory.
mktime() no longer accepts is_dst (day light saving) parameter.
preg_replace() function no longer supports “\e” (PREG_REPLACE_EVAL). preg_replace_callback() should be used instead.
exec() function has NULL byte protection now.
substr() now returns an empty string, if string is equal to start characters long.

New Global Constants


Core Predefined Constants






Timezone warning removed

Previously, a warning was emitted if the date.timezone INI setting had not been set prior to use any date- or time-based functions. Now, this warning has been removed (with date.timezone still defaulting to UTC).

Loosening Reserved Word Restrictions

There was a restriction of using globally reserved words as property, constant, and method names within the classes, interfaces, and traits. But those are now allowed.

// 'new', 'private', and 'for' were previously unusable

The “class” keyword still cannot be used for the above purposes.


PHP 4 style constructors

Methods defined with the name same as the class name is treated as the constructor, but no more! This is deprecated in PHP 7 and will be removed in the future releases. The PHP engine will emit E_DEPRECATED in this type of cases.
class foo {
function foo() {
echo 'this is the constructor method';

Static calls to non-static methods

Static calls to methods that are not declared static are deprecated, and may be removed in the future.
class foo {
function bar() {
echo 'Not a static method!';

By Supratim Roy

I'm a technology enthusiast with over fifteen years of hands-on work experience in the IT industry. My specialization in web development technology, allows me to quickly adopt innovative approaches and leading-edge technology solutions.

After passing the HS, I joined B.Com. under the CU. From the second year, I started studying computer courses. After graduating in Computer Applications (BCA) from Indira Gandhi National Open University (IGNOU), I started my career as a Jr. Software Dev. in 2005. After four years, in 2009, I got the opportunity to pursue a master's degree. In 2011, I completed MCA from Sikkim Manipal University (SMU). I carried out the journey of my carrier as Jr. Software Dev., Sr. Software Dev., TL, and PM. Now I'm working as the VP of Technology & Product at CodeClouds.

I use my technical knowledge, skill, expertise, and previous experience to analyze the requirements of the clients and understand their business philosophy. I try to deliver quality solutions and products in a timely manner with a high percentage of accuracy. I also prepare and manage project specifications, scope documentation, workflow, data diagram, and development documentation. I lead a team of around 50 highly talented members in a well-formed and structured way.

I love listening to music and watching the action, adventure, thriller, horror movies, and Discovery, Animal Planet, and Nat Geo TV channels. Photography is also one of my hobbies, however, I'm really an amateur! I like to read technical articles, journals, and documentaries about Indian Himalayas and wildlife. I'm passionate about adventure sports. I encourage peoples to love adventure sports.

I've traveled to many places and trekked in several parts of the Himalayas in India and Nepal. I'm a member of "MTG - Miles To Go" - a nature lover's association in Kolkata. I've done the Rock Climbing course from Parvat Abhiyatri Sangha affiliated with Anandabazar Patrika. I also participate in several community initiatives taken by an NGO.

Leave a Reply

Your email address will not be published. Required fields are marked *