Skip to content
DevMeme
7034 of 7435
PHP's Gender\Gender Class: Magic Integer Constants for Everything
Languages Post #7712, on Feb 15, 2026 in TG

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\Gender syntax means the class Gender inside the namespace Gender — namespaces group related code, but naming the only class after its namespace is like a folder named Reports containing one file named Reports.
  • 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 = 1GERMANY = 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

19
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. @sleepless_333 4mo

    Chat, is this real?

    1. dev_meme 4mo

      https://www.php.net/manual/en/class.gender.php

      1. @abel1502 4mo

        Oh, okay, the comment says this is for determining gender by first name

      2. @palaueb 4mo

        https://github.com/johnvandeweghe/Gender/blob/master/src/Gender.php

        1. dev_meme 4mo

          I assume engineers should be able to do two more clicks in documention Too much to assume?

  3. @sysoevyarik 4mo

    Femboy superiority confirmed ✅ IS_MOSTLY_FEMALE > IS_MALE > IS_FEMALE > BRITAIN

  4. @TarasPushkar24 4mo

    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 не смешной? Старожил: Понимаешь, анекдот то смешной, просто есть люди которые умеют анекдоты рассказывать, а есть те которые не умеют!

    1. @mihanizzm 4mo

      That's a nice one

    2. @azizhakberdiev 4mo

      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

      1. @TarasPushkar24 4mo

        Funniest part is that error_in_name is 69

  5. @M_Ali_S_S 4mo

    WHAT????

  6. @jMdZzZ 4mo

    «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

  7. @palaueb 4mo

    GRoK tell me where is the documentation please

  8. @hy60koshk 4mo

    * I'm too busy to joke about it myself, so here's an old thread where that guy has already nailed it *

    1. @deadgnom32 4mo

      but if he would just open an introduction section of this class — he would have realized, that he is completely missing the point.

      1. @hy60koshk 4mo

        And you've just misgendered them 🌚 Anyway, it's funny either way, especially the Kosovo thing

      2. dev_meme 4mo

        No-no-no, to ignore documentation is the best way to get some fun!

  9. @douglas_adams 4mo

    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

Use J and K for navigation