Skip to content

Add nullsafe arrow.#244

Closed
Crell wants to merge 5 commits intophp:masterfrom
Crell:nullsafe
Closed

Add nullsafe arrow.#244
Crell wants to merge 5 commits intophp:masterfrom
Crell:nullsafe

Conversation

@Crell
Copy link
Copy Markdown
Contributor

@Crell Crell commented Nov 26, 2020

I included a Note giving guidance on when to use it, because I keep fielding "but doesn't this just encourage bad error handling? questions from people. I figure this is a case where some usage guidance is warranted.

@Girgias
Copy link
Copy Markdown
Member

Girgias commented Nov 27, 2020

I think the token page and the language/operator page should also be update to include a mention/link to this page.

Other than that LGTM

@cmb69
Copy link
Copy Markdown
Member

cmb69 commented Nov 28, 2020

May prefer the term "nullsafe operator" over "nullsafe arrow"?

@iluuu1994
Copy link
Copy Markdown
Member

We do call it "nullsafe operator" and "nullsafe object operator" internally. I don't have a preference but I'd stick with one of the two.

@Crell
Copy link
Copy Markdown
Contributor Author

Crell commented Nov 28, 2020

I went with nullsafe operator for conciseness, and added it to the token list.

The -> operator is not in the operators page as is (one of the comments notes it), and it's not in the precedence list in zend_language_parser.y either, much to my surprise. That seems like a larger question to resolve than I want to get into here.

@cmb69
Copy link
Copy Markdown
Member

cmb69 commented Nov 28, 2020

The -> operator is not in the operators page as is (one of the comments notes it), and it's not in the precedence list in zend_language_parser.y either, much to my surprise. That seems like a larger question to resolve than I want to get into here.

I agree that this can be resolved another time.

Copy link
Copy Markdown
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left a few commits and applied with respective changes.

As of PHP 8.0.0, properties and methods may also be accessed with the
"nullsafe" operator instead: <literal>?-></literal>. The nullsafe operator
works the same as property or method access as above, except that if the
object being dereferenced is <literal>null</literal> then <literal>null</literal>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When referring to the null value, it's usually best to denote it as &null;.

</para>
<para>
<example>
<title>Class name resolution</title>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting example for "class name resolution". ;)

<![CDATA[
<?php

// This line in PHP 8.0:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets confusing when PHP 8.1.0 will be released: does it work only for PHP 8.0?

@php-pulls php-pulls closed this in 025f2d3 Nov 28, 2020
@Crell Crell deleted the nullsafe branch November 29, 2020 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants