DEV Community

Cover image for All the changes that come with PHP 7.4

All the changes that come with PHP 7.4

Carlos Gándara on December 01, 2019

PHP 7.4 is available since past 28th of November. This new update for PHP 7 version comes with some nice additions, another minor features and a bu...
Collapse
 
goceb profile image
Goce • Edited

Unfortunately, only contravariant arguments are supported so the command/handler example will not work:

interface Command{}

interface CommandHandler{
    public function handle(Command $command) : void ;
}

class KillAllHumans implements Command{}

class KillAllHumansHandler implements CommandHandler{
    public function handle(KillAllHumans $command) : void {}
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
xoubaman profile image
Carlos Gándara • Edited

You are right. Amazingly enough, I realized it in a conversation in some slack community at the same time you wrote the comment.

I will correct the article as soon as I can. Update: fixed!

Thanks for pointing it out!

Collapse
 
latengoyo profile image
alex #1Oct • Edited

I can't see the usefulness of contravariant VS covariant arguments. I guess there were some technical issues implementing covariant arguments.

I was hyped up with PHP 7.4 only for that!

Collapse
 
david_j_eddy profile image
David J Eddy

An excellent break down of the new feature set Carlos.

Collapse
 
xoubaman profile image
Carlos Gándara

Thanks! Glad you liked it :)

Collapse
 
zexias profile image
Matheus Faustino

Weak references is related to garbage collector basically, there are good examples of how to use it in nodejs and java. It helps the garbage collector identify what it can get, not when, but which objects/vars and etc...

It's a kind of feature that will help projects like doctrine, that can consume a lot of resources because of the references through objects and so on.

Did you get it or it was confused?

Collapse
 
xoubaman profile image
Carlos Gándara

Yup, I got the concept but couldn't find a real-life example. I guess I never had to deal with such type of functionality in any project, like holding big graphs of object relations.

Funny enough, Ocramius, a Doctrine core maintainer, voted against weak references feature 🤷‍♂️

Thanks for the comment!

Collapse
 
marinabsa profile image
Marina A.

Thanks for the article Carlos.
I‘m currently learning PHP and something intrigued me, why did you write
if(!($command instanceOf RegisterUserCommand)){} as if it would be the same as passing RegisterUserCommand as a parameter? Doesn‘t the exclamation inside the if statement mean „only if $command is not an instance of RegisterUserCommand“?

Collapse
 
nicolasdanelon profile image
Nicolás Danelón

thanks, awesome article!

Collapse
 
petecapecod profile image
Peter Cruckshank

Wow first off that elephant pic is 💯🤩
Great article 👐👐

Collapse
 
iarmankhan profile image
Arman Khan

Great Article Man!❤✨ Loved it!

Collapse
 
xoubaman profile image
Carlos Gándara

Thanks!

Collapse
 
marinabsa profile image
Marina A.

Oh nevermind, I see what you mean now. In my head you meant to check if it is an instance in the first place , but you are looking for the case that it isn’t in order to throw an Exception.

Collapse
 
xoubaman profile image
Carlos Gándara • Edited

Exactly. But not needed anymore :D

UPDATE: Actually no, the example was not correct :(

Collapse
 
xoubaman profile image
Carlos Gándara

Actually, my assumption was not correct, I have removed the example. Sorry for the confusion.

Collapse
 
xoubaman profile image
Carlos Gándara

I fixed an error in the underscore for numeric literals, the correct way is to use a dot for separating the decimal part. So 1000.50 is 1_000.50, not 1_000_50.

Collapse
 
pthreat profile image
pthreat

Well explained, well done