Hacker News new | ask | show | jobs
by itafroma 4102 days ago
Note this is just Zend's take on what's important in PHP 7: it's not a complete list.

A more comprehensive list:

- Dual-mode scalar type hints (weak by default, toggleable to strict via a per-file syntax) (https://wiki.php.net/rfc/scalar_type_hints_v5)

- Return type declarations (https://wiki.php.net/rfc/return_types)

- <=> operator (https://wiki.php.net/rfc/combined-comparison-operator)

- Null coalesce operator (??) (https://wiki.php.net/rfc/isset_ternary)

- Closure::call (https://wiki.php.net/rfc/closure_apply)

- Abstract syntax tree (https://wiki.php.net/rfc/abstract_syntax_tree)

- Context sensitive lexer, allowing the use of reserved words in more places (https://wiki.php.net/rfc/context_sensitive_lexer)

- Unicode escape syntax in strings (https://wiki.php.net/rfc/unicode_escape)

- A uniform variable syntax (https://wiki.php.net/rfc/uniform_variable_syntax)

- Expectations (https://wiki.php.net/rfc/expectations)

- Use declaration grouping (https://wiki.php.net/rfc/group_use_declarations)

- Removal of a ton of long-deprecated features

- Massive speed improvements

You can see everything that's been added to PHP 7 on https://wiki.php.net/rfc (look under Accepted and Implemented - PHP 7.0)

2 comments

OH man I want that Null coalesce operator so bad...
I feel like I've needed that since I first started coding PHP 17 years ago!
I feel like I want to test what happens if you put values like "", false, " ", 0, an empty array, etc etc etc in front of ??.

Because, you know, this is PHP.

> I feel like I want to test what happens if you put values like "", false, " ", 0, an empty array, etc etc etc in front of ??.

All of those would result in the variable being assigned those values: the null check uses the same semantics as is_null(), and the truth table for those values is:

    $v     is_null($v)
    ------------------
    ''     FALSE
    false  FALSE
    ' '    FALSE
    0      FALSE
    []     FALSE
If you want to all falsy values to use the fallback value, use the shorthand ternary operator (?:) instead.
Only null will return the default value. http://3v4l.org/jphnq
...Abstract syntax tree? I didn't know it was implemented without using AST. It surprises me, as I've been always told that ASTs are necessary to implement a compiler. Maybe there seem to be some alternatives?
> Maybe there seem to be some alternatives?

This is not meant to be an endorsement of this method, but PHP <7.0 uses a single-pass compilation where the parser itself does the opcode compilation. A lot of the buggy and quirky behavior PHP exhibits (at least when that behavior is unintentional) is the result of this process.

Like a lot of extant PHP, there's no real reason it was done this way: it's just the method Rasmus et al happened to program the original engine, and it's grown organically since then. With the AST, phpng, and the uniform variable syntax, I'd argue PHP7's main feature is finally getting around to correcting the sins of the past.

>A lot of the buggy and quirky behavior PHP exhibits (at least when that behavior is unintentional) is the result of this process.

A lot? Please stop spreading wrong info. In the words of an internal developer,

> It does fix a few minor points with regard to variables vs. expressions, but those aren't particularly important.

>"So, really, the whole thing has no direct effect on userland devs. It's an internal rewrite."

https://www.reddit.com/r/PHP/comments/2cc9xp/rfc_abstract_sy...

> A lot? Please stop spreading wrong info. In the words of an internal developer,

You may disagree with me saying "a lot", and that's fair, but I don't think it's fair to say it's "wrong info" and NikiC's characterization that it has "no direct effect on userland devs" is disingenuous, given the RFC lists several changes to syntax and behavior: https://wiki.php.net/rfc/abstract_syntax_tree#changes_to_syn...