20

Recently for a project I needed to read/write ID3 tags from MP3 files. And after a long search, I found this bloated, monolithic but quite stable library, "getID3".

So, I was looking through the code-base and I found this. This guy literally storing the key value based data embedded as comments within the class file. Then wrote a method to parse the data and even used caching to ensure maximum speed! And such usage is repeated all over the code-base.

So, this is what people used do before arrays were invented :3

Comments
  • 16
    This is the most PHP thing I've seen in a long time
  • 0
    @12bitfloat And I'm assuming you've seen a lot xD
  • 2
    🤦‍♀️
  • 2
    Fucking ninja!
  • 10
    "Why does PHP have a bad reputation?"
  • 3
    Is someone reading the data from the PHP file itself?

    There are very care cases where introspection like that might be desired. Very very rare.

    This one doesn't make much sense. It's the kind of thing you might see if you have to do something in one file and there's enough memory to parse it but not keep it in memory.
  • 0
  • 1
    Thats.. a bit weird, but not actually rare.
    golang has a similar problem.

    Say you want to include a dataset - Json, or protobuf format in your public OSS lib. But you can't do it directly - lang specs dictate libs are pure code. So.... you turn your dataset into a const in your code. byte arrays, or huge longass comments like this one.
  • 1
    However it was written, it works!

    The beauty of computer programming.
  • 0
    @RANTSMCPANTS Yeah but the list is not too long, probably 20 key => value paired data, one just could store the value in an array within the same class. Storing as comment and then parsing the file line by line and even caching seems overkill.
  • 0
    @pai-shinoda Yeah, I'm amazed that this library still works just fine with almost zero errors even with PHP7.
  • 1
    PHP supports embedding data (eg. some binary data) at the end, and even has some magic constants or functions for that.

    I dont remember their names, but this guy is doing it wrong.

    Not that I support the practice anyway, but it's there.
  • 2
    @Quirinus I guess you're talking about the __halt_compiler(); function, but that is for binary data, this is is just key => value pair small enough to be stored in an array or a JSON file.
  • 0
    What the fuck
Add Comment