- This topic has 6 replies, 1 voice, and was last updated 2 months, 3 weeks ago by Namoshek.
- October 27, 2020 at 4:54 am #886HyperDanonParticipant
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?October 27, 2020 at 4:54 am #887asshole667Guest
Refactor. Rename your class.October 27, 2020 at 4:54 am #888AllenJB83Guest
> 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](https://www.php.net/mailing-lists.php) or [read it online](https://externals.io/). There’s also a few sites / services that monitor RFCs such as [RFC Watch](https://php-rfc-watch.beberlei.de/) and the [Twitter RFC bot](https://twitter.com/PHPRFCBot))
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.October 27, 2020 at 4:54 am #889Flibbertygibbety22Guest
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.October 27, 2020 at 4:54 am #890ahundiakGuest
What does your Match class do? The English language is a funny thing. Match could mean Compare. Or it could mean Game.October 27, 2020 at 4:54 am #891SoeyKittenGuest
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?October 27, 2020 at 4:54 am #892NamoshekGuest
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.
- You must be logged in to reply to this topic.