Leave a Reply

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

Notify of
avatar

SOHEL AHMED MESANIYA
Guest
SOHEL AHMED MESANIYA
5 months 11 days ago

Hi,I would like to know how you get this fancy error in form of table with background colour red and yellow in your browser? Are you using xampp? I am using LAMP (php 7.1) in Ubunut 16.04. Is there any chances for me to get this type of formatted errors in browser in my above mentioned environment. I would appreciate your help. Thanks

Kale
Guest
Kale
6 months 23 days ago

The text/code could have been a bit bigger.

Manolis Agkopian
Guest
Manolis Agkopian
6 months 28 days 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
6 months 28 days 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
6 months 28 days ago

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

Codecourse
Guest
Codecourse
6 months 28 days 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
6 months 28 days ago

Here's how I set everything up 🙂

wpDiscuz