PHP 8 won’t be compatible with my lib – what to do?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #886

    I’m developing a library, which 80% of use-cases is `Match` class.

    But in PHP 8, there comes match expressions (better switch), which will introduce `match` keyword. Which means my class `Match` will be a compile-error.

    The only thing I can think of is:
    – Not support PHP 8 (bad idea)
    – Rename the class (hard to find a suitable replacement)
    – Use pseudo-name (e.g. `_Match`) (bad idea)
    – Write to PHP devs not to include `match` keyword, but maybe `when` like in Kotlin?

    Do you guys have any idea what I could do?


    Refactor. Rename your class.


    > Write to PHP devs not to include match keyword, but maybe when like in Kotlin

    It’s far too late for this. PHP 8 is already feature frozen and the devs won’t be making any such changes at this point.

    And if they did change it, they’d end up with some other library conflicting. Unless its completely obscure, someone always gets affected when new keywords are added.

    (If you want to follow along with PHP’s development to get earlier warning of such changes, you can subscribe to the [internals mailing list]( or [read it online]( There’s also a few sites / services that monitor RFCs such as [RFC Watch]( and the [Twitter RFC bot](

    Languages adding new reserved keywords is just a fact of life you’re going to have to put up with.

    Your best option, as per other posts, is to select a different naming convention.


    Without knowing much about your library, my first thoughts would be to rename it. You could either find a synonym for match, or use a completely different like how `Carbon` is a date library.


    What does your Match class do? The English language is a funny thing. Match could mean Compare. Or it could mean Game.


    No: Your lib won’t be compatible with PHP8. Expecting PHP to change for you won’t get you very far. Your work is not that important.

    also, wasn’t there also an RFC that solves this issue by treating the whole FQN as a token instead of each individual part? is that not part of php8?



    If your class is called `Match` *as verb*, then the naming is wrong (an object cannot be a verb) and you should change it to `Matcher` (*not a word though comprehensible*) or `Comparator` for example.

    If your class is called `Match` *as noun*, `MatchResult` is probably a suitable replacement for it.

    Anyhow, renaming is the way to go. These are just suggestions.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.