|
|
Log in / Subscribe / Register

PHP struggles with attributes syntax

PHP struggles with attributes syntax

Posted Aug 7, 2020 5:09 UTC (Fri) by flussence (guest, #85566)
In reply to: PHP struggles with attributes syntax by Cyberax
Parent article: PHP struggles with attributes syntax

Every syntax addition to PHP since 2005 feels like it's been forced by either a legacy design decision to use an ad-hoc giant switch statement parser for speed on CGI hosting, or an aversion to doing anything remotely risky for long-term benefit.

It became clear to me something wasn't right when namespaces were introduced; of all the possibilities and prior art out there, they instead went with *backslashes*.


to post comments

PHP struggles with attributes syntax

Posted Aug 7, 2020 5:29 UTC (Fri) by burki99 (subscriber, #17149) [Link] (2 responses)

I was originally also very irritated by the backslashes. About 10 years later, everybody is using them, and together with composer, they are huge success story. So I assume the same will happen with attributes, once the syntax is settled, people will get used to them, no matter which variant will be accepted.

PHP struggles with attributes syntax

Posted Aug 8, 2020 19:45 UTC (Sat) by smurf (subscriber, #17840) [Link] (1 responses)

Yeah, but that would have been a success with any other reasonable character. And, well, a backslash is only reasonable if you've been socialized on Windows. On Unix its connotation with "escape whatever special meaning the next character has" is too strong for me to feel comfortable with the thing.

PHP struggles with attributes syntax

Posted Aug 13, 2020 11:03 UTC (Thu) by flussence (guest, #85566) [Link]

> And, well, a backslash is only reasonable if you've been socialized on Windows.

A subset of windows users at that. Japanese Win/DOS had ¥ everywhere \ was used. It's probably baked in as a hard alias for compatibility nowadays.

PHP struggles with attributes syntax

Posted Aug 7, 2020 6:11 UTC (Fri) by ibukanov (subscriber, #3942) [Link]

I also found the backslashes felt as not right. Backslashes in Haskell did not felt that way because the rest of language is so different. But foo\bar was so foreign in a language based on C syntax. Yet as a maintainer of a small website using PHP I strongly appreciate that the code written sensibly 15 years ago still works as is.

PHP struggles with attributes syntax

Posted Aug 8, 2020 5:43 UTC (Sat) by iteratedlateralus (guest, #102183) [Link] (2 responses)

The backslashes definitely weren't something I totally agreed with. I recall being in #php on Freenode, and saying that the backslash was too much of a shock (especially since it's an escape sequence). I said it would be use if they instead used the :: (the infamous php operator that I can't pronounce).

Something like:

use App::Models::FooBar;

The current syntax, for those who aren't php devs, is:

use \App\Models\FooBar;

PHP struggles with attributes syntax

Posted Aug 8, 2020 21:21 UTC (Sat) by jkingweb (subscriber, #113039) [Link] (1 responses)

While you probably know this now, that would have been ambiguous. Is ::foo:::bar::baz() a a call to a function in the ::foo::bar namespace, or to a method of class bar in the ::foo namespace?

PHP struggles with attributes syntax

Posted Aug 9, 2020 6:57 UTC (Sun) by iteratedlateralus (guest, #102183) [Link]

That's very true. Had it not been the static access operator, it might work.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds