Skip to content
DevMeme
7034 of 7590
Languages Post #7712 · source on Telegram

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

20
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. Anonymous

    Gender\Gender achieves type safety by returning an int and asking society to memorize the ASCII table.

  3. @sleepless_333 6mo

    Chat, is this real?

    1. dev_meme 6mo

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

      1. @abel1502 6mo

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

      2. @palaueb 6mo

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

        1. dev_meme 6mo

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

  4. @sysoevyarik 6mo

    Femboy superiority confirmed ✅ IS_MOSTLY_FEMALE > IS_MALE > IS_FEMALE > BRITAIN

  5. @TarasPushkar24 6mo

    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 6mo

      That's a nice one

    2. @azizhakberdiev 6mo

      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 6mo

        Funniest part is that error_in_name is 69

  6. @M_Ali_S_S 6mo

    WHAT????

  7. @jMdZzZ 6mo

    «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

  8. @palaueb 6mo

    GRoK tell me where is the documentation please

  9. @hy60koshk 6mo

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

    1. @deadgnom32 6mo

      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 6mo

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

      2. dev_meme 6mo

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

  10. @douglas_adams 6mo

    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