Skip to content
DevMeme
2008 of 7590
Languages Post #2237 · source on Telegram

PHP's documentation maintaining its usual level of precision

Description

A screenshot of the official-looking documentation for the PHP `count()` function. The header 'count' is shown in purple text, followed by a dotted underline. Below, it indicates compatibility with '(PHP 4, PHP 5, PHP 7)'. The function's description reads: 'count - Count all elements in an array, or something in an object'. The humor lies in the extremely vague and unprofessional phrase 'or something in an object'. Technical documentation is expected to be precise and unambiguous, but this wording is the opposite, playing directly into the long-running stereotype of PHP having inconsistent and poorly defined language features. This resonates deeply with senior developers who have historical context of PHP's evolution and its reputation for quirks

Comments

13
Anonymous ★ Top Pick I see PHP is still using the 'I have no idea what this does to objects but it returns a number so ship it' philosophy for its core functions
  1. Anonymous ★ Top Pick

    I see PHP is still using the 'I have no idea what this does to objects but it returns a number so ship it' philosophy for its core functions

  2. Anonymous

    PHP manual: count() counts elements in an array - or “something” in an object. After 20 years of duct-taping Countable, Traversable, and magic __get(), even the docs have adopted our code-review strategy: ship it and let prod figure out what “something” means

  3. Anonymous

    "Count all elements in an array, or something in an object" - the exact level of type safety that led to three rewrites, two migrations, and one CTO asking why our API returns different counts depending on the phase of the moon

  4. Anonymous

    Ah yes, PHP's count() function: 'Count all elements in an array, or something in an object.' That 'or something' is doing more heavy lifting than a microservice architecture at a FAANG company. It's the documentation equivalent of 'TODO: figure this out later' that somehow shipped to production in 2000 and has been there ever since. Senior engineers know that 'or something' translates to 'implements Countable, or returns 1 for objects that don't, except when it returns 0, or throws a warning, depending on which PHP version's mood swings you're dealing with today.' It's the kind of spec ambiguity that makes you appreciate strongly-typed languages with exhaustive documentation - or at least makes you understand why your architect insists on wrapping every PHP built-in in a well-tested abstraction layer

  5. Anonymous

    PHP’s count(): arrays return cardinality; objects return “something” - either 1, a warning, or whatever your Countable decides, depending on which decade your codebase was written

  6. Anonymous

    PHP's count(): Arrays get precision engineering; objects get 'or something' - the original lazy interface spec

  7. Anonymous

    Only PHP docs can define count() as handling arrays… or “something in an object” - which is exactly how our PHP 5 → 7.2 migration spec read until Countable showed up with a clipboard

  8. @a_sulf 5y

    😂

  9. @Flam_Su 5y

    Ну да. Интерфейс Countable предпологает свободную реализацию: public function count():int { return 4; }

    1. @AndreyProgr 5y

      Код из прода?))

    2. @Flam_Su 5y

      нет на проде private const COUNT = 4; public function count():int { return self::COUNT; }

      1. @ognotme 5y

        лол

      2. @PsLXd 5y

        Выпал

Use J and K for navigation