PHP's Gender\Gender Class: Magic Integer Constants for Everything
Why is this Languages meme funny?
Level 1: The Secret Decoder Ring Nobody Gave You
Imagine a vending machine where the buttons are labeled "70", "77", and "63" instead of "cola", "water", and "mystery flavor." The numbers actually do mean something — they're the first letters of the drink names, converted to a secret code — but the machine never tells you that. You can memorize the numbers and get by, yet you'll always feel like the machine is messing with you. That's this documentation page: the answers make perfect sense to whoever built it thirty years ago, and to absolutely no one since.
Level 2: Magic Numbers and Why They Bite
A magic number is a bare numeric literal whose meaning isn't explained by the code around it. Constants are supposed to fix this — IS_MALE is more readable than 77 — but here the constant's value still leaks into logs, databases, and APIs, where someone eventually stares at a 109 with no idea it means "mostly male." This is why modern languages prefer enums: closed sets of named values where the underlying number is an implementation detail you never see.
- PECL is PHP's repository of C extensions — compiled add-ons that bolt third-party libraries onto the language. Quality and API style vary wildly because each extension mirrors whatever C library it wraps.
- The
Gender\Gendersyntax means the classGenderinside the namespaceGender— namespaces group related code, but naming the only class after its namespace is like a folder namedReportscontaining one file namedReports. - Early-career lesson hiding here: when an API returns weird numbers, check an ASCII table before assuming randomness. Inherited code often encodes meaning in ways the documentation forgot to mention.
Level 3: 'F' Wearing a Trench Coat
What looks like arbitrary chaos in this php.net screenshot — const int IS_FEMALE = 70;, const int IS_MOSTLY_FEMALE = 102;, const int IS_MALE = 77;, const int IS_MOSTLY_MALE = 109; — is actually a worse kind of chaos: hidden cleverness. These are ASCII codes. 70 is 'F', 102 is 'f', 77 is 'M', 109 is 'm', 63 (IS_UNISEX_NAME) is '?', 67 (IS_A_COUPLE) is 'C', 32 (NAME_NOT_FOUND) is a literal space character, and 69 (ERROR_IN_NAME) is 'E'. The PECL gender extension wraps an old C library (a port of the German gender.c name-classifier) that returned single result characters, and the PHP binding faithfully exposed those chars as their integer code points — then documented them as bare magic numbers with no hint of the encoding. Lowercase letters meaning "mostly" is a genuinely cute convention in 1990s C; surfaced as const int in 2020s documentation, it reads like the API was generated by rolling dice.
The class name is its own punchline. Gender\Gender exists because PECL extensions got namespaced mechanically — extension name becomes namespace, class keeps its name — producing the redundant stutter that PHP critics collect like trading cards (Spl anyone?). Then there's the country list: ANY_COUNTRY = 0, BRITAIN = 1 … GERMANY = 12, a hardcoded enumeration frozen in whatever order the original dataset shipped in. Germany at 12 despite the dataset being famously German-built is the kind of detail that tells you nobody designed this; it accreted.
The deeper satire is about PHP's standard-library archaeology. The core language has spent two decades modernizing — the banner in the screenshot proudly announces PHP 8.5.3, a language with enums, readonly properties, and fibers — yet the documentation still hosts these fossils with a straight face. A modern API would return enum Gender { Female, MostlyFemale, ... }. Instead, downstream code ends up with if ($result === 70) and a comment nobody trusts. And that's before you reach the conceptual problem: guessing gender from a first name is exactly the kind of feature that seemed like neutral data plumbing in 1999 and now reads as a design review nobody would survive — IS_A_COUPLE as a return value for a single name lookup deserves its own incident retrospective.
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
19Comment 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
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