Should hash comments be deprecated?

  111672
August 21, 2020 17:28 theodorejb@outlook.com (Theodore Brown)
Hi internals,

Since the #[] attribute syntax is currently winning the vote, [1]
it makes me wonder if the use of comments starting with # should be
deprecated.

Otherwise it seems like we could be setting ourselves up for long-term
confusion between attributes and comments, and also inconsistency with
other comments (it will no longer be safe to assume that a line can be
commented out by simply adding # at the beginning).

What do others think?

Theodore

[1]: https://stv-results.theodorejb.me/php/?rfc=shorter_attribute_syntax_change
  111674
August 21, 2020 21:08 ajf@ajf.me (Andrea Faulds)
Hi,

Theodore Brown wrote:
> Hi internals, > > Since the #[] attribute syntax is currently winning the vote, [1] > it makes me wonder if the use of comments starting with # should be > deprecated. > > Otherwise it seems like we could be setting ourselves up for long-term > confusion between attributes and comments, and also inconsistency with > other comments (it will no longer be safe to assume that a line can be > commented out by simply adding # at the beginning). > > What do others think? > > Theodore > > [1]: https://stv-results.theodorejb.me/php/?rfc=shorter_attribute_syntax_change >
There is a critical use-case for comments beginning with the hash symbol, namely UNIX shebang lines. In theory we could special-case those and disallow the symbol in every other use, but… well, that seems like a bit of a shame. Regards, Andrea
  111676
August 21, 2020 21:12 tysonandre775@hotmail.com (tyson andre)
Hi Theodore,

> Since the #[] attribute syntax is currently winning the vote, [1] > it makes me wonder if the use of comments starting with # should be > deprecated. > > Otherwise it seems like we could be setting ourselves up for long-term > confusion between attributes and comments, and also inconsistency with > other comments (it will no longer be safe to assume that a line can be > commented out by simply adding # at the beginning). > > What do others think?
I don't use # comments in practice that much, and objected to `#[`, but I'd imagine there'd be two main objections. 1. Most significantly, existing code would break in the major version where the deprecation became an error. So libraries that stopped being maintained in 2020 or earlier would all either need to be forked (and forks would have to be published to composer), locally checked in, be affected by a post-install script, etc - non-technical users of PHP applications may not do that and delay upgrade to php 9.0 or 10.0. I imagine there may be very strong objections to that from others, but may be wrong, since the invalid # comments would be easy to check for and automatically fix. 2. Now that we're probably going to reuse `#` for one thing, we may end up using it for other things that would benefit from forwards compatibility now that applications are already forced to deal with this lexing change.. ------ Some examples of what php developers hypothetically could do by continuing to repurpose #. (I have no plans to put any of these forward as RFC) ``` declare( strict_types = 1, #php8.1 very_strict_something = 1 // #php8.1 could be a token that's treated like the end of a comment in php 8.1+ ) #[attribute] function() {/*unused closure*/}; some new php81_syntax(); // a more concise, self-explanatory version of the above that could be used in more places. #php8.1 some new php81_syntax(); // A version of assert that is guaranteed not to throw with any ini settings // and that can be optimized out in php.ini-production #expect($condition); // Adding a forward compatible syntax to declare that an argument is passed by reference // i.e. https://wiki.php.net/rfc/explicit_send_by_ref function inc(&$i) { $i++; } // instead of inc(&$i); // one of these could also be done inc(/* & */$i); inc( // or #byref #& $i ); ``` Regards, - Tyson
  111679
August 21, 2020 21:58 marandall@php.net (Mark Randall)
On 21/08/2020 18:28, Theodore Brown wrote:
> Since the #[] attribute syntax is currently winning the vote, [1] > it makes me wonder if the use of comments starting with # should be > deprecated.
I've mentioned this myself in R11 a few times and was planning on bringing this up to a vote myself as soon as we started for 8.1 I think it makes perfect sense, there's no reason why we need both // and # and if #[] wins out as it looks like it will, that's even more reason to deprecate #. There's an easy upgrade path too with a perfect substitution, and so far as I can tell the only breakage would be if people were using external code to do pre-processor like operations such as using #start and #end as quasi-tags. Ideally, if we pass #[ ] we would deprecate # in the same version and put it on the fast-track to removal, but that would require an additional vote. Mark Randall