Skip to content
DevMeme
2008 of 7435
PHP's documentation maintaining its usual level of precision
Languages Post #2237, on Nov 6, 2020 in TG

PHP's documentation maintaining its usual level of precision

Why is this Languages meme funny?

Level 1: Counting Toys vs Counting a Friend

Imagine you have a toy box filled with action figures. If I ask you to count all the toys in the box, you can open it up and count 1… 2… 3… and tell me the number. That’s easy and clear, right? 📦✨ Now, imagine I point to your best friend standing next to you and say, “Also, count… something in that friend.” Huh? 🤨 You’d probably tilt your head and ask, “Count what in my friend? Their fingers? Their candies? The number of jokes they know?” It’s a pretty silly request because it’s not clear at all what you’re supposed to count inside a person!

That confusion you feel is exactly why this picture is funny. In a rule book for a programming language (like instructions for a game), they wrote an instruction that’s super clear for one thing (toys in a box, easy!) but totally unclear for the other (something in your friend? What does that even mean?). Normally, instruction books try to be very exact — just like a teacher giving precise homework directions. But here, it sounds like the book itself got a bit confused or gave up trying to explain. So developers reading it giggle because it’s as if the book said, “Count all the stuff in this one case, or… I dunno, something in that other case.” It’s funny in the same way it would be if your teacher said, “Do all the math problems on this page, or do something on the next page” – you’d laugh and think, “Wait, what something am I supposed to do?”

In simple terms, the meme is joking about unclear instructions. We expect clear language when learning or following rules. When we see “or something…” in an official guide, it’s like seeing an adult shrug and say, “figure out something yourself.” It just sounds wrong and silly. So, just as you’d chuckle if someone told you to count an unclear “something” in your friend, programmers laugh seeing that phrasing in the PHP manual. It’s a lighthearted reminder that even the big official rulebooks can have a sense of humor (accidentally or not)!

Level 2: Counting Arrays vs Objects

So, what’s actually happening with count() in PHP? Let’s break it down in simpler terms. In PHP (a popular programming language for web development), count() is a built-in function that tells you how many items are in a collection. If you give count() an array, it will return the number of elements in that array. An array in PHP is like a list of items (it could be a list of numbers, strings, etc. – PHP arrays are super flexible). For example, if you have an array of three names, count($namesArray) would return 3 because there are three elements. That part is easy and intuitive. ✅

Now, if you give count() an object instead, things get weird. An object in PHP is an instance of a class – think of it like a little bundle that can have its own properties (variables inside it) and methods (functions it can do). But an object isn’t automatically a list of things. By default, an object doesn’t have a clear “length” the way an array does. This is where the PHP documentation’s “or something in an object” comes from. It sounds confusing because, well, counting an object is confusing in PHP!

Here’s the deal: PHP decided long ago that calling count() on an object shouldn’t cause a big error, even if it’s not obvious what to count. Instead, PHP will try its best to return a number. If the object is a special kind that knows how to count its contents (technically, if it implements the Countable interface – basically a built-in way for an object to say “here’s how many items I have inside me”), then count($thatObject) will call that internal counting logic and give you a meaningful number. For example, imagine an object that represents a collection of songs – if it implements Countable, it might return the number of songs it holds. Cool!

But if the object isn’t designed to be counted – like a plain stdClass object that you or I didn’t specifically outfit with counting ability – PHP historically would just return 1 by default. It’s as if PHP says, “We have one object here.” In older PHP versions this happened silently; in modern PHP 7+, it’ll still return 1 but also pop up a warning message saying (paraphrasing), “Warning: count(): Parameter must be an array or an object that implements Countable”. That warning is PHP’s way of hinting, “This object doesn’t really have anything countable inside, so counting it is kind of meaningless.”

So why did the official documentation use such a vague phrase like “something in an object”? It’s because the behavior depends on the situation, and explaining it briefly is tricky. The manual is basically saying: “count() will count all elements in an array (easy), or do something when you give it an object.” The “something” is a placeholder for “whatever counting means for that object.” If the object is a countable container, the “something” is the number of things inside it. If the object isn’t meant to be counted, the “something” is just 1 (like one object counted as a single unit). The phrasing is definitely odd – and that’s exactly why developers find it funny. It’s a little embarrassing for an official manual to sound so unsure! Normally, documentation is very precise, so this stands out as documentation humor.

For a junior developer or someone new to PHP, this can be puzzling. You might think, “Wait, what do you mean count something in an object? What thing?” 🤔 Don’t worry – you’re not alone! The community itself made a meme out of this because it struck a chord. It highlights a language quirk where PHP’s flexibility leads to a not-so-clear definition. In practical terms, as a newcomer you just need to remember: use count() for arrays or things meant to act like arrays (like objects that are specifically made countable). If you try to count a regular object, PHP will give you a fallback value (usually 1) and possibly a warning. It’s PHP’s way of trying to be helpful (or at least not crash your program), but it can definitely be confusing at first.

To sum it up, the meme is pointing out the funny way the PHP manual phrased this behavior. It’s basically an inside joke among developers: “Even PHP’s own manual isn’t exactly sure how to explain counting objects!” Understanding this joke gives you insight into PHP’s nature: very convenient and forgiving, but sometimes a bit ambiguous in its language reference. And as you continue coding, you’ll discover every programming language has its own little oddities – PHP’s count() just happens to be one that’s both useful and meme-worthy. Keep an eye on those official docs; every now and then, they reveal more than just facts – sometimes they reveal the personality of the language and its history!

Level 3: Countable Conundrum

At first glance, the PHP manual’s description of the count() function reads like a punchline: “Count all elements in an array, or something in an object.” Seasoned developers can’t help but smirk at the phrasing. It’s official documentation, yet it sounds unsure about its own language feature! This bit of ambiguous documentation hints at a deeper language quirk that has left many of us either chuckling or groaning (or both).

Why would the PHP docs say "or something"? The answer lies in PHP’s storied history of pragmatism and backwards compatibility. In PHP, arrays are straightforward: you count() an array and you get the number of elements. Easy. But objects? That’s where the “something” comes in. PHP objects aren’t inherently countable like arrays. Back in the PHP 4 and early PHP 5 days (not exactly a golden age of rigorous type safety), calling count() on a plain object didn’t throw an error – PHP would blithely return 1. In other words, it would count the object itself as one big thing. Why 1? Because PHP basically shrugged and treated any object as a single unit unless told otherwise. This kept old scripts from crashing – a classic PHP move to prioritize “just work” behavior over strict accuracy.

Over time, PHP introduced the Countable interface (in PHP 5) to let objects define what counting means for them. If an object implemented Countable (with a count() method inside), then count($object) would defer to that and return whatever the object wanted to count (e.g. the number of items it contains internally). If an object didn’t implement Countable, PHP continued its tradition: return 1 (and in newer PHP 7+ versions, also emit a mild warning to nudge developers – “Hey, this object isn’t really countable…”). Essentially, count() on an object could either be a meaningful number (if the object says so) or a default 1 (if PHP has no clue). How do you summarize that in one documentation line? 🤷‍♂️ The manual author seemingly gave up on being precise and went with “...or something in an object.” It’s as if the PHP language reference itself sighed and admitted the behavior is a bit vague.

This juxtaposition is the core of the humor. Precise language is expected in manuals, yet here we have official docs sounding like a StackOverflow answer edited at 3 AM. Experienced PHP devs share a knowing laugh because they’ve lived through these oddities. It’s documentation humor that resonates: we’ve all seen warts in our favorite languages, and PHP’s loosey-goosey type system has produced gems like this. The meme is poking fun at how even PHP’s own docs can’t elegantly justify a quirky design decision made decades ago. It’s a coding humor time capsule of PHP’s evolution – from PHP 4’s wild-west approach to PHP 7’s slightly more strict checks – all compacted into one hilariously non-committal sentence.

To really appreciate the count conundrum, consider a quick example:

$array = [1, 2, 3];
$object = new stdClass();

echo count($array);   // Outputs 3  (elements in the array)
echo count($object);  // Outputs 1  (an object counts as "1")

In the code above, counting the array makes perfect sense (there are 3 elements). Counting a generic object returns 1 – not because there’s truly one “element” inside, but simply because PHP has to return... well, something. Now, if that $object implemented Countable (or was a special object like a SimpleXMLElement that overrides counting), then count($object) might return a different number (like the number of child elements in an XML, for instance). The manual’s author opted for wording that covers all bases without detailing each case – resulting in a strangely casual vague specification.

For veteran developers, this meme brings back memories of wrestling with PHP’s idiosyncrasies. It highlights the documentation humor in the incongruity: a formal manual sounding like it threw its hands up. We’ve come to expect such quirks from a language that’s famously inconsistent at times (remember the needle-haystack parameter order flips? sigh). The “or something in an object” line perfectly captures that shared “PHP, you’ve done it again” feeling. It’s funny because it’s true – and because it’s written in black-and-white on php.net for all to see. In the world of DeveloperHumor, this is PHP proudly wearing its scars. Even the reference page carries a hint of stand-up comedy, intentionally or not, about how counting in PHP isn’t as simple as 1-2-3. The community laughs not out of malice, but out of recognition: we’ve all been there, reading official docs with raised eyebrows, realizing that sometimes the best the docs can say is, “yeah... it counts something.”

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