در حال بارگذاری ...

Dynamic Class Name Syntax0:00

Let's now return to the example from the NullSafeOperator lesson, where we set up what is effectively a lookup table. Anyways, I'm going to point your attention right here. This is where we accept an object, and we figure out the full class name, including the namespace. Now, traditionally, you may know, if you have the class, then you can tack on this right here to get that full path. However, if you're not working with the class itself, but instead the object, this did not work. Let's prove it.

PHP 7 vs 8 Demo0:30

work. Let's prove it. In php 7, I'm going to run it, and it fails. Cannot use class with dynamic class names. However, in php 8, you can. Have a look. Down here, we will vardump the type, give it a run, and it works. And fun little fact, this particular RFC passed 60 to 0. Everyone agreed it was a good idea. So yeah, once you upgrade your own code base, you might want to do a full project search.

Refactoring get_class Usage0:54

Everyone agreed it was a good idea. So yeah, once you upgrade your own code base, you might want to do a full project search for any references to get class. And if you find any, you can replace them with this syntax, because they are functionally identical. And while you're there, if you come across any switch references, yeah, just refer back to the NullSafeOperator lesson, where we swap those over to match expressions. So together, they form a fun little example that is entirely new in php 8.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟