9

man, fuck php.
fuck fucking php fuckitily fucking hard.
basically every fuckin stdlib function it has is fucked in some way.
can't even remember it anymore properly, but...

for example:
explode(" ", "some string like this ");

function to "split a string into array of strings using the first param as the boundary marker.

the above one would return
["some", "string", "like", "this", ""]

BECAUSE I'M FUCKING FUCKITTY SURE THAT WHEN THE LAST CHARACTERS OF THE STRING ARE EQUAL TO THE SEPARATOR STRING, EVERYONE WANTS TO GET BACK ONE EXTRA FUCKING USELESS EMPTY ITEM IN THE ARRAY.

because beyond the last wall of my house, there's another room of my house, you stupid Lerdorf fuck.

Comments
  • 6
    luckily, there's a handy array_filter function, that takes in an array, and removes all emp... oh, wait, no, it removes all FALSY items, so also say goodbye to your "0" and "false" items, if you had any.
  • 5
    They probably fixed this with a different method, but left the broken one in there for someone to find and fix all over again later. PHP is that mental old woman who hasn't thrown anything out since 1988 and has to fight her way through piles of rubbish to get to her own toilet.
  • 9
    That's expected behaviour.

    And as far as I know, it's the same behaviour in any language...

    Just apply trim (or strip in Python) before exploding....

    ?!!!!
  • 11
    what are you talking about? this is standard behaviour in pretty much every language I worked with... You can't leave dangling separators or it's gonna split them up even if the followup is an empty string

    JavaScript:

    "foo bar ".split(" ")

    >result: Array(3) [ "hello", "world", "" ]

    Python:

    "foo bar ".split(" ")

    >result: ['foo', 'bar', '']

    C#:

    String[] arr = "Hello World ".Split(' ');

    Console.WriteLine("[{0}]", string.Join(", ", arr));

    >result: [foo, bar, ]

    Actually, weirdly enough, the only language I found that doesn't do this is Java

    "foo bar ".split(" ");

    >result: ["foo", "bar"]

    or

    "foo bar ".split("\\s");

    >result: ["foo", "bar"]

    I'm gonna go on a limb here and say that the only reason why java does it is because it uses regex for splitting instead of simple character splitting

    Tbh, I'm more surprised about Java than PHP

    The standard way to handle this is to call trim() first...
  • 2
    Now that is an outright wrong example.
    But yes, the stdlib of PHP is fucked up in all imaginable ways.

    Switch to Python or wrap each required stdlib function to abstract the inconsistencies and other subtleties away.
  • 3
    What really killed me is that Lerdorf back then chose the names of standard functions so that they would distribute better across the hash buckets. But the ultimate level of stupidity was that he abused the string length as fucking hash function!
  • 4
    you know fuckidilidy programmer ... trim()
  • 5
    So you being inept is somehow PHP’s fault? Ok then...
  • 1
    i just need some vacancy ... like everyone of us
  • 3
    In c# you can add parameter to tell if you want empty entries or not
  • 1
    This is what every language I've used does too..
  • 5
    Bad example. But yes, PHP is indeed a steamy pile of contagious rhino diarrhea.
  • 7
    Every time I see a PHP rant I always drop by for the comments section above all else.
  • 4
    Like virtually any language that has this ability, one must RTFM and understand the expected output.

    explode(" ", trim(" this is a string Whoot "));

    There problem solved, or you know, don't explode spaces and have shitty data.
  • 3
    Write tests.

    Also, for real PHP issues: http://phpsadness.com/
  • 4
    ThIs Is Da ZaMe in EvEry lAnG, but Yi fk php hueheuheheu

    y'all make no fucking sense i swear 🤣🤣🤣🤣
  • 1
    @Midnight-shcode so you blame array_filter that takes an actual function to do EXACTLY what you want for having a very convenient default functionality that does not solve your own fuck-up.
    To top it off this is all perfectly documented.

    Regarding your OP just about any language you take issue with. Perhaps you are broken and undocumented not PHP.
  • 0
    I just realized you can't import code from a parent directory in Python without hacks unless you install it system* wide first. PHP's `require` ftw!

    *) venv is still a system, just virtualised
  • 2
    @cprn i know! And to import python in sub folder you need to create empty __ini__.py for fuckall
  • 0
    @jak645 only if you need backwards compatibility to pre 2012 versions of python. Since 3.3 you have namespaced packages and don't need the file unless you really want to init something.
  • 0
    @AleCx04 c# which is still the least crappy language i know has a parameter to filter out the empty entries...
  • 0
    @C0D4 c# which is still the least crappy language i know has a parameter to filter out the empty entries...
  • 0
    @YADU c# which is still the least crappy language i know has a parameter to filter out the empty entries...
  • 0
    @Hazarth yeah well firstly what do i call when my separator is not a space?

    secondly, you sneakily ignored that c# has a parameter to tell it to filter the empty ones out. not ideal, but much better.
  • 0
    @Midnight-shcode my point still stands, this isn't a php issue exactly. It isn't even rare.

    Also I didn't know about the C# flag! Good to know. Though im not using C# as much last couple of years.
  • 2
    @Midnight-shcode explode() does have a limit flag, so you could do something like

    explode(" ", "this is a bad string ", -1);

    which would output:
    Array
    (
    [0] => this
    [1] => is
    [2] => a
    [3] => bad
    [4] => string
    )

    however you would need to know to expect that last element to be blank, theres some drawbacks using the limit flag if you dont know your data.

    another means would be to use array_filter()
    https://php.net/manual/en/...

    Of array_walk() if you need to write your own sanitizer Due to php's falsly way of doing things

    By doing so you can remove the blank elements of the array after you explode() it, bit of double handling, but since your intent is to not clean the data first, we need to do it after the fact now.
  • 2
    @Midnight-shcode like @C0D4 said, "since your intent is not to clean the data first, we have to do it aft the fact now"

    Language ain't the issue here baby girl.
  • 2
    love-hate for PHP will divide entire DevRant into 2 equal halves
Add Comment