1

In previous version of PHP we have code comments written like

#[Socket panel]

After Updating to PHP 8 we are getting Error

syntax error, unexpected identifier "panel", expecting "]"

Is this bug in new PHP 8 or i am missing something ? Is there any solution to support older comment.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
Arun Verma
  • 139
  • 1
  • 11
  • Those are not comments in PHP 8 but attributes [attributes](https://www.php.net/releases/8.0/en.php#attributes) – Remy Feb 02 '21 at 14:25
  • 3
    Does this answer your question? [Can I use a hash sign (#) for commenting in PHP?](https://stackoverflow.com/questions/9093609/can-i-use-a-hash-sign-for-commenting-in-php) – El_Vanja Feb 02 '21 at 14:26
  • The accepted answer in the duplicate has been updated to reflect on attributes. – El_Vanja Feb 02 '21 at 14:27
  • Got it, find and replace all :) – Arun Verma Feb 02 '21 at 14:30

2 Answers2

2

In PHP 8 you have now Attributes which are used in the following style #[Testclass] this is why you get this error.

https://stitcher.io/blog/attributes-in-php-8

You have to change that comments to another style.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
1

As of the new PHP 8, those aren't comments, they're Attributes.

They've changed the Attribute syntax from <<attr>> to #[attr]. (See this.)

Maytha8
  • 846
  • 1
  • 8
  • 26
  • 1
    Actually, the result of that RFC was a change from `<>` to `@@attr`; there was then [_yet another RFC_](https://wiki.php.net/rfc/shorter_attribute_syntax_change) which changed it to `#[attr]` after a long debate and about a dozen different suggestions. But that was all before 8.0.0, so all anyone needs to know is that `#[attr]` is the syntax that actually got "released". – IMSoP Feb 03 '21 at 18:39