Leave a Reply

6 Comments on "What’s new in PHP 7.1: Nullable types (2/12)"

Notify of
avatar

Kale
Guest
Kale
6 days 16 hours ago

The text/code could have been a bit bigger.

Manolis Agkopian
Guest
Manolis Agkopian
10 days 18 hours ago

I think it's worth mentioning that you can actually have nullable type hinted parameters even before PHP 7.1, you just need to give the parameter a default value of null. For example the following code will work just fine, and won't give you any errors,<?phpclass Foo {}class Bar { public function foobar ( Foo $foo = null ) { //… }}$bar = new Bar;$bar->foobar();

Codecourse
Guest
Codecourse
10 days 2 hours ago

Good shout, although that's not really type hinting NULL, you're right about it working the same. Sometimes I want to say, "I only expect an instance of null or Foo" without the default value.

Vady
Guest
Vady
10 days 18 hours ago

What editor are you using? it looks really neat, and is it better than phpstorm?

Codecourse
Guest
Codecourse
10 days 2 hours ago

And I like PHPStorm, but Sublime is a better option if you like less configuration to make your environment less cluttered.

Codecourse
Guest
Codecourse
10 days 2 hours ago

Here's how I set everything up 🙂

wpDiscuz