Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeremykendall/d270cb041f5c7c5e8889 to your computer and use it in GitHub Desktop.
Save jeremykendall/d270cb041f5c7c5e8889 to your computer and use it in GitHub Desktop.
What is this technique called?

I was talking to a friend tonight about a particular flavor of syntax error in another language. It reminded me of the below behavior in PHP. I know there's a name for this technique/syntax/idiom, but I have no idea what that name is. Anyone?

$ php -a
Interactive shell

php > echo new DateTime()->format('Ymd');
PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in php shell code on line 1

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in php shell code on line 1
php > echo (new DateTime())->format('Ymd');
20151030
php > exit
@jeremykendall
Copy link
Author

It's called "class member access on instantiation" and it was introduced in PHP 5.4. Thanks, @MethyleneGaming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment