PHP's Gender\Gender Class: Magic Integer Constants for Everything
Description
A screenshot of the official php.net documentation (mobile view, with the PHP logo header and a 'PHP 8.5.3 Released!' banner) for 'The Gender\Gender class' from the PECL gender extension (PECL gender >= 0.6.0). The class synopsis shows a wall of integer constants: IS_FEMALE = 70, IS_MOSTLY_FEMALE = 102, IS_MALE = 77, IS_MOSTLY_MALE = 109, IS_UNISEX_NAME = 63, IS_A_COUPLE = 67, NAME_NOT_FOUND = 32, ERROR_IN_NAME = 69, followed by country constants ANY_COUNTRY = 0, BRITAIN = 1, IRELAND = 2, USA = 3, SPAIN = 4, PORTUGAL = 5, ITALY = 6, MALTA = 7, FRANCE = 8, BELGIUM = 9, LUXEMBOURG = 10, NETHERLANDS = 11, GERMANY = 12. The humor targets PHP's legendarily chaotic standard library design: a redundantly namespaced 'Gender\Gender' class that guesses gender from first names and returns opaque magic integers (which are actually ASCII codes - 70 is 'F', 77 is 'M', 63 is '?', 69 is 'E') instead of enums or readable values
Comments
20Comment deleted
Only PHP would model gender as an ASCII char cast to int - IS_FEMALE = 70 isn't a magic number, it's just 'F' wearing a trench coat
Gender\Gender achieves type safety by returning an int and asking society to memorize the ASCII table.
Chat, is this real? Comment deleted
https://www.php.net/manual/en/class.gender.php Comment deleted
Oh, okay, the comment says this is for determining gender by first name Comment deleted
https://github.com/johnvandeweghe/Gender/blob/master/src/Gender.php Comment deleted
I assume engineers should be able to do two more clicks in documention Too much to assume? Comment deleted
Femboy superiority confirmed ✅ IS_MOSTLY_FEMALE > IS_MALE > IS_FEMALE > BRITAIN Comment deleted
Why the fuck country and gender are on the same class? Why the fuck do you need to assign integers to it? Reminds me of this russian joke Лежат зеки на нарах после отбоя. Вдруг из одного угла слышится: 27. Вся камера: бу-га-га! Из другого угла: 34. Камера опять ржет. Новенький зек спрашивает у лежащего рядом старожила: А че это за цифры из-за которых все в камере смеются? Старый отвечает: Понимаешь, кореш, давно тут сидим, все анекдоты уже рассказали и, чтобы не повторять каждый раз, присвоили им номера. Называет кто-то номер анекдота, а все остальные вспоминают и смеются. Новенький на всю камеру: 17. Тишина, никто не смеётся. Он опять к старожилу: А что анекдот под №17 не смешной? Старожил: Понимаешь, анекдот то смешной, просто есть люди которые умеют анекдоты рассказывать, а есть те которые не умеют! Comment deleted
That's a nice one Comment deleted
it classifies names by gender and country At first I thought these are flags, because unisex name is 0b11111, but the rest didn't really match Comment deleted
Funniest part is that error_in_name is 69 Comment deleted
WHAT???? Comment deleted
«Gender PHP extension is a port of the gender.c program originally written by Joerg Michael. The main purpose is to find out the gender of firstnames. The current database contains >40000 firstnames from 54 countries. » https://www.php.net/manual/en/intro.gender.php Comment deleted
GRoK tell me where is the documentation please Comment deleted
* I'm too busy to joke about it myself, so here's an old thread where that guy has already nailed it * Comment deleted
but if he would just open an introduction section of this class — he would have realized, that he is completely missing the point. Comment deleted
And you've just misgendered them 🌚 Anyway, it's funny either way, especially the Kosovo thing Comment deleted
No-no-no, to ignore documentation is the best way to get some fun! Comment deleted
const int KAZAKH_UZBEK = 46; this is my favorite gender BTW the original code on C is there: https://github.com/cstuder/genderReader/blob/master/gender.c/gender.c#L193 Comment deleted