PHP 7
PHP 7 is the most awaited and is a major feature release of PHP programming language. PHP 7 was released on 3rd Dec 2015. This tutorial will teach you the new features of PHP 7 and their usage in a simple and intuitive way.Audience
This tutorial has been prepared for PHP developers from a beginner’s point of view. After completing this tutorial, you will find yourself at a moderate level of expertise in the knowledge of PHP from where you can take yourself to next levels.
Prerequisites
We assume that you already know about the older versions of PHP and now you can start learning the new features of PHP 7.
Execute PHP-7 Online
For most of the examples given in this tutorial, you will find an option Try it. Just use this option to execute your PHP-7 programs at the spot and enjoy your learning.
What is PHP 7?
PHP 7 is a major release of PHP programming language and is touted to be a revolution in the way web applications can be developed and delivered for mobile to enterprises and the cloud. This release is considered to be the most important change for PHP after the release of PHP 5 in 2004.
New Features
There are dozens of features added to PHP 7, the most significant ones are mentioned below −
Improved performance − Having PHPNG code merged in PHP7, it is twice as fast as PHP 5.
Lower Memory Consumption − Optimized PHP 7 utilizes lesser resource.
Scalar type declarations − Now parameter and return types can be enforced.
Consistent 64-bit support − Consistent support for 64-bit architecture machines.
Improved Exception hierarchy − Exception hierarchy is improved.
Many fatal errors converted to Exceptions − Range of exceptions is increased covering many fatal error converted as exceptions.
Secure random number generator − Addition of new secure random number generator API.
Deprecated SAPIs and extensions removed − Various old and unsupported SAPIs and extensions are removed from the latest version.
The null coalescing operator (??) − New null coalescing operator added.
Return and Scalar Type Declarations − Support for return type and parameter type added.
Anonymous Classes − Support for anonymous added.
Zero cost asserts − Support for zero cost assert added.
PHP 7 uses new Zend Engine 3.0 to improve application performance almost twice and 50% better memory consumption than PHP 5.6. It allows to serve more concurrent users without requiring any additional hardware. PHP 7 is designed and refactored considering today's workloads.
A great PHP 7 course based resource where users can learn about PHP 7 fundamentals. This course breaks down PHP 7 in small short videos to help users even newbies who are just getting started with PHP to understand the latest iteration. Not only that, but the course will also include a project that includes putting the fundamentals into practice and actually seeing how to use them.
What Happened to PHP 6?
When told the next major version is 7 while we’ve been developing on 5+ so far, many wonder what happened to version 6. It’s a long story, so to avoid looking confused when this is brought up, here are some interesting discussions and posts as required reading:
In short, the unicode problems that were supposed to be solved in version 6 ultimately failed, with too many added complications, and this kind of ruined things for everyone. It was decided that version 6’s rep was too damaged to keep it alive, and a move to PHP 7 was made.
New Features
We’ve spoken about the new features briefly before, but here’s a more comprehensive list of links to information about them – now’s the time to dive in and get ready.
To learn about what’s coming and what an impact it might have on you:
Getting Started with PHP 7
If you’re not of the VM sort, to install PHP 7 on the most recent version of OS X,
If you are, however, there’s Jump Start PHP Environment – a book by yours truly, edited and reviewed by the venerable Ross Tuck. It’s a short book on getting started before code – learning about requests, responses, virtual machines, and all the other important server and local development machine setups. The book helps prepare you to write platform-agnostic code, and makes it possible for others to just jump into your team at a whim.
Paid intro course from Zend – good for people familiar with PHP 5 who don’t mind shelling out some cash
Official migration guide from 5.x
Erika’s excellent post on DigitalOcean
Various compatibility checkers and converters are available:
PHP7MAR (Migration Assistant Report) will report any inconsistencies between your current code base and PHP 7, so you can plan and budget your upgrade path
php7ize is a code fixer that tries to add PHP 7 features into a PHP 5 codebase automatically
php7cc (Compatibility Checker) will try and do the same things as the MAR above – compare their outputs for the most reliable results.
It should be noted that none of the tools above are a replacement for a good test suite – the only way to be 100% certain there’s no bugs left behind is to cover your code with tests so it can be easily inspected and verified during migration.
Last but not least, PHPToday have put together an absolutely fantastic list of talks which you can take a look at here.
Comments