Home / News & Technology / PHP 7 – Meet to new face of your partner :)

PHP 7 – Meet to new face of your partner :)

Are you looking for the latest status, news, articles, features or updates about the newest version after PHP 5.X? After a long voting process by the community, the name for the next major PHP version has been finalized! The winning proposal is to call the latest major version PHP 7. So here’s some major things you must know about PHP 7!

PHP 7 will be released later this year

The PHP 7 Timeline RFC was approved in a near unanimous vote, and aims to release PHP 7 in October 2015. Even if it’s delayed a bit, we’re still likely to see it before the year is out!!

. See the PHP 7 timeline

PHP Space Ships

PHP 7 will introduce a new operator <=> conveniently similar to a TIE fighter and dubbed the Spaceship Operator. It can be used for combined comparisons – mostly when dealing with sorting. See more info

Return Type Declarations & Scalar Type Hints

PHP 7 will allow developers to declare what kind of return type a function is expected to have – similar to argument Type Hints.

In addition, argument type hints and the new return-type declarations now support new scalar types, allowing developers to denote that they’re expecting strings, floats, ints or bools to be passed or returned. See Scalar Type Hints

For you, as end-users, what this means is that you can now type-hint with scalar types. Specifically: int, float, string, and bool. By default type-hints are non-strict, which means they will coerce the original type to the type specified by the type-hint. This means if you pass int(1) into a function that requires a float, it will be come float(1.0). Passing float(1.5) into a function that requires an int, it will be come int(1).

Here’s an example:

 

Additionally, you can enable strict mode by placing declare(strict_types=1); at the top of any given file will ensure that any function calls made in that file strictly adhere to the types specified. Strict is determined by the file in which the call to a function is made, not the file in which the function is defined.

If a type-hint mismatch occurs, a Catchable Fatal Error is thrown:

 

Furthermore, PHP 7 also supports Return Type Hints which support all the same types as arguments. These follow the same syntax as hack, suffixing the argument parenthesis with a colon followed by the type:

 

In this example the : bool indicates that the function will return a boolean.

The same rules that apply to type-hints apply to returned type hints for strict mode.

PHP 7 Performance

The biggest reason for upgrading to PHP 7 is it’s performance, brought primarily with the changes introduced as phpng. The performance increases may in fact ensure quick adoption, especially from smaller hosts who would normally not do so, as they will be able to host more customers on the same hardware.

As things currently stand, depending on whose benchmark you see, the performance of PHP 7 is on par with Facebooks HHVM, which features a Just In Time (JIT) compiler that compiles PHP code all the way down to machine instructions (if it is able).

PHP 7 does not feature a JIT, though it has been discussed a lot. It is unclear if there are more performance gains to be had with the addition of one, but it sure will be interesting to see if someone decides to create one!

In addition to performance, there should be substantial memory savings, as optimization of internal data structures is one of the primary ways in which performance improvements have been achieved.

PHP 7 is 2X faster

Since PHPNG was open sourced and later merged into PHP 7, its performance more than doubled in many cases, and we’re continuing to improve it all the time.

To put things in perspective – when PHPNG was published, the WordPress homepage required approx. 9.4 billion CPU instructions to execute. As of now – it requires only 2.6 billion – that’s 72% less!

PHP 7 is 2X faster

Since PHPNG was open sourced and later merged into PHP 7, its performance more than doubled in many cases, and we’re continuing to improve it all the time.

To put things in perspective – when PHPNG was published, the WordPress homepage required approx. 9.4 billion CPU instructions to execute.  As of now – it requires only 2.6 billion – that’s 72% less!

Replacing current json extension with jsond

The current Json Parser in the json extension does not have a free license which is a problem for many Linux distros. This has been referenced at Bug #63520. That results in not packaging json extension in the many Linux distributions.

Skipping Optional Parameters for Functions

Every now and then PHP has a little chat about named parameters, and last time a great RFC popped for that. That RFC is on ice for now, but this “Skip Params” RFC popped up trying to give people some of the same functionality without actually making named params.

While I am glad Stas went to the trouble of making this, I am so much more glad that people downvoted it. It’s a band aid solution to named parameters, and I really hope we see them for later versions of PHP 7.x.

Constructor behaviour of internal classes

Cleanup undesirable behaviour of constructors internal classes.

PHP is well known for having inconsistencies in its codebase and PHP 7 is trying to fix a huge number of these things. One such inconsistency is how some internal class constructors behave with failures:

 

That’s fairly messed up right there, as you’d expect either an object back, or an exception to be thrown.

There are a bunch of other oddities that this RFC looks to clean up, and by documenting the intended behavior it means if any other classes are found to be acting up they can be treated as bugs and fixed.

Attention to detail like this is helping PHP 7 become a really strong version, and takes a lot of wind out of the trolls sails.

Reclassify E_STRICT notices

This RFC proposes to reclassify the few existing E_STRICT notices and remove this error category.

PHP has way too many error types. The cognitive load required to new developers of PHP, and even to seasoned pros, is a nightmare. There are edge cases and confusion all around.

E_STRICT alone is a bit of a weird one.

Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. Since PHP 5 but not included in E_ALL until PHP 5.4.0

Ugh. This RFC suggests killing off usage of E_STRICT errors, and recategorising them as one of the following:

  • Remove the strict standards notice if it appears inconsistent or informational.
  • Promote to E_DEPRECATED if there is intent to remove this functionality in the future.
  • Promote to E_NOTICE or E_WARNING otherwise.

Strict Argument Count On Function Calls

This RFC proposes to sensibly add a strict argument count check for function calls on PHP7

This one is very controversial. Right now in PHP, if you have a method that expects 3 arguments and you shove a 4th in there, it’ll accept the value and carry on with no warnings, errors or anything.

Some consider that a bug.

Some consider that a feature.

I fully agree with the RFC author:

Strict checks on argument counts are good to catch bugs (sometimes dangerous bugs) on user space code. According to measurements presented on this RFC, done by running many FOOS projects test suites, the current PHP silent behavior is not helpful and we should fix it.

Relying on the fact that PHP will let you sneak extra arguments in to satisfy some interface which should just be updated to me seems like a weird edge case, but some very smart developers rely on that too. It’s hard to say one way or the other, but I always think the more PHP can have our backs and alert us of problems, the easier it becomes to maintain larger systems.

There have been a few discussions about changing things in this RFC, so it might end up pulled and tweaked. If the RFC is not pulled, I’d say its chances are about 50/50 of getting done.

Anonymous Class Support

Anonymous classes can be used to make insanely simple implementations to satisfy interfaces without having to run off to the autoloader or jam a bunch of classes in the same file.

These anonymous classes are also pretty damn good at mocking, so PHP will have to do far fewer gross things to get mocked objects.

 

This RFC is another Joe Watkins and Phil Sturgeon production. Joe likes to write the code, but doesn’t always have the time or energy to get things through the RFC procedure. I help out by writing tests, handling the RFC wiki entry, gathering feedback, discussing changes, etc.

About cmadmin

Web Developer & Designer | Android App Developer

Check Also

Subdomain and Mandomain

Create Dynamic Subdomains using PHP and Htaccess

Dynamic subdomains like Google Blogger and Tumblr.com, I know the vast majority of the general …

frameworks-banner

How to make your own PHP framework?

Building your own framework can be useful for the following reasons: You can learn a …

4 comments

  1. google analytics api

    Wow that was unusual. I just wrote an very long comment but after I clicked
    submit my comment didn’t appear. Grrrr… well I’m not writing all that over again.
    Anyhow, just wanted to say wonderful blog!

  2. Hi there, just became alert to your blog through Google, and
    found that it is truly informative. I’m golnna watch out for brussels.
    I will be grateful if you continue this in future. Many people
    will be benefited from your writing. Cheers!

  3. Its such as you learn my thoughts! You appear to grasp so much about this,
    like you wrote the e-book in it or something.
    I think that you simply could do with some p.c. to
    drive the message house a bit, however instead of that, this is excellent blog.
    A great read. I’ll definitely be back.

  4. I visit everyday several blogs and websites to learn articles or reviews,
    however this website provides quality based posts.

Leave a Reply

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

Login


Username
Create an Account!
Password
Forgot Password? (close)

Sign Up


Username
Email
Password
Confirm Password
Want to Login? (close)

Forget Password?


Username or Email
(close)
%d bloggers like this:
SHARE
OR
SUBSCRIBE
To get latest new / tutorial / technology / development information subscribe with us.
ARE YOU READY? GET IT NOW!
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !
OR SUBSCRIBE WITH