# Should hash comments be deprecated?

- Thread: https://externals.io/message/111672
- Original archive: https://news-web.php.net/php.internals/111672
- Started by Theodore Brown on 2020-08-21T17:28:07+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #111672 — Theodore Brown — 2020-08-21T17:28:07+00:00

URL: https://externals.io/message/111672#111672

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 — Andrea Faulds — 2020-08-21T21:08:24+00:00

URL: https://externals.io/message/111672#111674 · In reply to: #111672

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 — tyson andre — 2020-08-21T21:12:27+00:00

URL: https://externals.io/message/111672#111676 · In reply to: #111672

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 `#<rest>` 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

---

## #111677 — Ilija Tovilo — 2020-08-21T21:13:42+00:00

URL: https://externals.io/message/111672#111677

Hi Andrea

> 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.

Correct me if I'm wrong, but the shebang goes before the PHP opening
tag <?php and thus this is not relevant. In fact, shebang is already a
special case.

https://github.com/php/php-src/blob/f32653accc0fc2401aca91f9590272b8d95ef426/Zend/zend_language_scanner.l#L2155

Ilija

---

## #111679 — Mark Randall — 2020-08-21T21:58:38+00:00

URL: https://externals.io/message/111672#111679 · In reply to: #111672

> 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

---

## #111708 — tyson andre — 2020-08-29T17:22:26+00:00

URL: https://externals.io/message/111672#111708 · In reply to: #111677

Hi internals,

If it turns out that the impact on legacy applications, legacy libraries, or holding back upgrades is a concern for others
(I'm not sure what the most common opinion is),
another option would be a system ini setting

`hash_comment = 0|1|2`
0 - disable `#comment` support completely when parsing/lexing - throw a ParseError while lexing and return T_ERROR in token_get_all
1 - (default) emit a compilation warning or deprecation notice when parsing files mentioning that hash comments will be removed in a future major release. Do this only for the first comment.
2 - allow it silently (possibly an unnecessary option to provide)

Then, this could be gradually strictened

- Forbid option 2 in php 8.x
- change the default ini setting value to 0 in 8.x or 9.0
- Add a configuration setting in php 8.x or 9.x to always disable hash comments
- Remove support 

> Correct me if I'm wrong, but the shebang goes before the PHP opening
> tag <?php and thus this is not relevant. In fact, shebang is already a
> special case.

Yes, shebang can only be parsed on the first line of a script - before `<?php` sections.

Thanks,
- Tyson

---

## #111709 — David Rodrigues — 2020-08-29T19:25:40+00:00

URL: https://externals.io/message/111672#111709 · In reply to: #111708

I have suggested on past a declare() to help in cases like that:

declare(php_version = "8.0");

It could be declared to new PHP files, so old files could supports # as
comments and new files will not.

Other option is supports <?php8 syntax. And for future <?php81 for 8.1, so
on.

Em sáb, 29 de ago de 2020 14:22, tyson andre <tysonandre775@hotmail.com>
escreveu:

> Hi internals,
>
> If it turns out that the impact on legacy applications, legacy libraries,
> or holding back upgrades is a concern for others
> (I'm not sure what the most common opinion is),
> another option would be a system ini setting
>
> `hash_comment = 0|1|2`
> 0 - disable `#comment` support completely when parsing/lexing - throw a
> ParseError while lexing and return T_ERROR in token_get_all
> 1 - (default) emit a compilation warning or deprecation notice when
> parsing files mentioning that hash comments will be removed in a future
> major release. Do this only for the first comment.
> 2 - allow it silently (possibly an unnecessary option to provide)
>
> Then, this could be gradually strictened
>
> - Forbid option 2 in php 8.x
> - change the default ini setting value to 0 in 8.x or 9.0
> - Add a configuration setting in php 8.x or 9.x to always disable hash
> comments
> - Remove support
>
> > […]
>
> Yes, shebang can only be parsed on the first line of a script - before
> `<?php` sections.
>
> Thanks,
> - Tyson
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111710 — tyson andre — 2020-08-29T19:50:05+00:00

URL: https://externals.io/message/111672#111710 · In reply to: #111709

Hi David,

> Other option is supports <?php8 syntax. And for future <?php81 for 8.1, so on. 

That doesn't work when php-src is compiled with support for short_open_tags. It's treated as `<?` followed by the name `php81`.

Nikita Popov also brought up the possibility of editions months ago for an unrelated RFC, I'm not sure of the syntax.
https://externals.io/message/108699

Revisiting my earlier suggestion, starting off by just deprecating them without configuration options in 8.1 might be the most straightforward to start off with proposing,
and the migration path for removal can be revisited years from that.

Regards,
- Tyson
