loading...

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... [Read Full]
markdown guide
 

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 {}
}
 

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!

 

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!

 
 

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?

 

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!

 

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“?

 
 

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.

 

Exactly. But not needed anymore :D

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

 

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

 

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.

 
 
 

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

code of conduct - report abuse