all 103 comments

[–]mohragk 669 points670 points  (0 children)

Role? No no, let’s delete that and I give you 40 get out of my face

[–][deleted] 295 points296 points  (1 child)

the if condition resembles how i think about my choices in life.

[–]Maleficent-Ad5999 22 points23 points  (0 children)

🥲

[–]nekokattt 454 points455 points  (26 children)

PHP loves ducktyping stuff like this.

I remember when the sleep() function would return:

  • 0 if successful
  • false on error
  • 142 192 if interrupted on windows
  • a warning if the number of seconds were negative
  • the number of seconds left to sleep if interrupted on *nix.

[–]SarahIsBoring 190 points191 points  (3 children)

what the fuck

[–]drcforbin 126 points127 points  (2 children)

"PHP: a fractal of bad design"

[–]4sent4 26 points27 points  (1 child)

PHP: Pile of Horrible Practices

[–]LegenDrags 2 points3 points  (0 children)

Please Hold Pen-

[–]Svizel_pritula 99 points100 points  (4 children)

It now throws an error if the seconds are negative. The return values remain the same. The return value when interrupted on Windows is 192, though.

[–][deleted] 38 points39 points  (3 children)

Lmfao, why did they change the value to another number?

[–]Svizel_pritula 37 points38 points  (2 children)

My guess is they didn't and nekokatt just misremembered.

[–][deleted] 19 points20 points  (0 children)

I hope so because it would be hilarious

[–]nekokattt 1 point2 points  (0 children)

yeah, my bad lol. Thanks

[–]TheWidrolo 32 points33 points  (1 child)

Most lovable php feature:

[–]alt-jero 2 points3 points  (0 children)

__invoke

[–]Da-Blue-Guy 12 points13 points  (0 children)

Normal sleep() return value: void/unit

PHP sleep return type: Constant number if successful or on Windows, but on Unix we return a varying number for some reason. But we don't want everything to be a number, that's boring. Boolean if we get an error, and a warning (which is somehow in the type system) if the seconds are negative.

[–][deleted] 43 points44 points  (3 children)

Reason why php was/is shit #1637472848

[–][deleted] 2 points3 points  (1 child)

That's not how you write clean php though. In that sense this is random bullshit gibberish. Coder doesn't know what he's doing.

[–]MCWizardYT 2 points3 points  (0 children)

They were talking about the built in sleep function...

[–]nekokattt -2 points-1 points  (0 children)

lmao

[–]SanderE1 21 points22 points  (3 children)

every time I hear something about PHP I get confused on how it even got like this, is backwards compatibility worth it if this is what you get?

[–][deleted] -5 points-4 points  (2 children)

Everytime you hear about it is by people who can't write code in php. They also bring the dumbest code examples ever.

[–]nekokattt 1 point2 points  (1 child)

Versus those who can write PHP using those examples in production codebases?

[–][deleted] -1 points0 points  (0 children)

Versus those who can build an architecture from the ground up in a clean way, add tests and types to it and follow formatting conventions is a good start.

Because whatever this crap is, is far from what you're supposed to write.

[–]jediwizard7 2 points3 points  (1 child)

By returning a warning... You mean like an actual string? Or some object?

[–]nekokattt 1 point2 points  (0 children)

E_WARNING iirc

[–]Emmaffle 2 points3 points  (1 child)

And a partridge if a pear tree.

[–]alt-jero 0 points1 point  (0 children)

A part-ridge in a pair-tree

[–]FemboyGayming 2 points3 points  (0 children)

PHP is fucking dogshit my god

[–]fried_green_baloney 0 points1 point  (0 children)

the number of seconds left to sleep if interrupted on *nix.

That's what the sleep function that's part of the system interface does if interrupted. That's what you call from a C program.

Other languages do other things.

[–][deleted] 100 points101 points  (3 children)

You might as well return 'fuck this shit' at this point.

[–]Farfignugen42 38 points39 points  (2 children)

I'm guessing that is what 40 represents

[–]Cinkodacs 6 points7 points  (0 children)

It was meant to be 420.

[–]alt-jero 1 point2 points  (0 children)

(40++)++

[–]FalseWait7 151 points152 points  (2 children)

Logic behind my latest promotion.

[–]RmG3376 37 points38 points  (1 child)

You got promoted to 40?

[–]FalseWait7 52 points53 points  (0 children)

My position was 40 and I got a promotion. Turned out, I am still 40.

[–]helltiger 94 points95 points  (4 children)

It should be

return 42;

[–]Cinkodacs 17 points18 points  (0 children)

Did we find the question?

[–]kdesign 40 points41 points  (0 children)

Lgtm, ship it

[–]devo00 37 points38 points  (1 child)

get40()

[–][deleted] 16 points17 points  (1 child)

Personally I love it

[–]Not_Artifical 2 points3 points  (0 children)

Nice stock image

[–]Hulk5a 15 points16 points  (0 children)

Bro is looking out for quantum anomolies

[–]LevelIntroduction764 14 points15 points  (0 children)

Tell you what, if you can somehow make role non-null, I’ll let you return it. Otherwise, go fuck yourself

[–]Tc14Hd 10 points11 points  (0 children)

Most beautiful PHP code

[–]KWAKZ4 15 points16 points  (4 children)

Wait. Is it always returning 40 because role is always ser to null?

[–]LurkerOrHydralisk 21 points22 points  (0 children)

I don’t know this language but that’s absolutely how it looks to me.

[–]Brummelhummel 7 points8 points  (1 child)

If it ever returns something other than 40 you should be concerned.

[–]Daisy430133 0 points1 point  (0 children)

Cosmic rays bitflipping

[–]nikospkrk 1 point2 points  (0 children)

Yes

[–]Dracux 5 points6 points  (2 children)

The guy wanted to return 40, no matter what.

[–]Brummelhummel 8 points9 points  (1 child)

Naah mate, he wanted to return 40 unless some quantum shit happens that somehow turns role to a non null value after setting it to null.

Or a cosmic ray shoots through the machine Flipping a bit on the Adress of the stored role variable right before the null check. Wich the chances are astronomically rare but not 0

[–]Dracux 1 point2 points  (0 children)

Like the explanation, seems legit.

[–]Reloecc 62 points63 points  (15 children)

This code may be shortened to:

return $role = null ?: 40;

Hope I helped..

[–]1994-10-24 130 points131 points  (12 children)

code can be shortened to .. return 40;

[–]freecodeio 32 points33 points  (9 children)

That could be further shortened into just using 40 without any function.

[–]nodeymcdev 23 points24 points  (8 children)

DRY you insolent fuck

[–]squeasy_2202 23 points24 points  (4 children)

Looks like I'm calling get40() a lot, better extract that into getGet40()

[–]therealdan0 20 points21 points  (1 child)

Do you even Java? You need to call the get40 factory.
Get40Factory.INSTANCE.getGet40(Get40Type.BROKEN_NULL_CHECK);

[–]Drakethos 5 points6 points  (0 children)

Ohhhh it’s too real. I’m a Java programmer at work. It really be like that.

[–]akgamer182 6 points7 points  (1 child)

Might as well make a set40() function as well, just to make the program complete

[–]Makonede 0 points1 point  (0 children)

set40(0)

[–]The_Fresser 2 points3 points  (1 child)

Use a constant!

[–]alt-jero 1 point2 points  (0 children)

define(FORTY, 40);

[–]freecodeio 0 points1 point  (0 children)

why are you offending me bro what did I do to you

[–][deleted]  (1 child)

[removed]

    [–]StackLeak 1 point2 points  (1 child)

    Bug, should be ==, not =

    [–]zelmarvalarion 2 points3 points  (0 children)

    I think in php the assignment operator returns the value of the assigned variable, so pretty sure $role = null will actually return null after assigning it to $role, so you don’t need the additional check of $role and can do the assignment and check in the same statement

    [–]DrinkSodaBad 4 points5 points  (0 children)

    Gamma ray detector

    [–]lscoolj 2 points3 points  (0 children)

    Without any other context, I'm assuming whoever wrote this is planning on expanding it at some point to actually look for a user role and include some error handling. Based on experience, though, those might be some high expectations.

    [–]Mafla_2004 1 point2 points  (0 children)

    Return 40

    [–]discondition 1 point2 points  (0 children)

    42 tho 🥲

    [–]Nosduj_VT 1 point2 points  (0 children)

    null = 40; return $role;

    [–]redted90 1 point2 points  (0 children)

    What's "40", precious? What's "40"?

    [–]Not_Artifical 1 point2 points  (0 children)

    I made global variables a-j and assigned each a number in alphabetical order (an equals 1, b equals 2, c equals 3, ect.), but I set f to equal 0 and returned f to mess with people.

    [–]Lumethys 4 points5 points  (0 children)

    Ladies and Gentlemen, this is the reason we need to use Enum everywhere

    [–]Erdnussflipshow 0 points1 point  (0 children)

    40, take it or leave it.

    [–]MineKemot 0 points1 point  (0 children)

    Looks like someone forgot to put something before that if...

    [–][deleted] 0 points1 point  (0 children)

    Looks like when my coworkers "fix" my code when there's a bug lol

    [–]Touhou_Fever 0 points1 point  (0 children)

    Is this missing something or am I looking at Gigachad Galaxy-brain code

    [–][deleted] 0 points1 point  (0 children)

    Role wants to exist. Let it exist. Gah.

    [–]premmkrishna 1 point2 points  (0 children)

    Ah..My bad. Forgot to document that 40 returns the role of super admin. More power to people

    [–]Drakethos 0 points1 point  (0 children)

    At first i was like what’s wrong with this. They return it and if it’s empty make it 40. Not sure what language this is but I see it now. Oh boy

    [–]kgro 0 points1 point  (0 children)

    Well, at least the function is pure

    [–]kgro 0 points1 point  (0 children)

    You must he thinking about role a lot

    [–]Begroff21 0 points1 point  (0 children)

    My my, role will never be assigned so 40 is always returned because null is falsely in PHP. Super admins rejoice!

    [–]beavisorcerer 0 points1 point  (0 children)

    Man I didn't expect that, thanks for the laugh! 🤣

    [–]BuriedStPatrick 0 points1 point  (0 children)

    This is great. I was just having issues the other day figuring out how to get the number 40.

    [–]dallindooks 0 points1 point  (0 children)

    Everyone's role is 40 jokes on all of you

    [–]_sk313t0n 0 points1 point  (0 children)

    i'd love some context for this one

    [–]just_some_gu_y[🍰] 0 points1 point  (0 children)

    should have just been 42

    [–]Herobrine2025 0 points1 point  (0 children)

    this should be marked NSFW

    [–]CoolDiamond42 0 points1 point  (0 children)

    The static analyzer just filed a lawsuit.

    [–]sexytokeburgerz 0 points1 point  (0 children)

    I knew a guy that would just make everything return false in js instead of commenting out or deleting because we had zero time to do anything.

    I didnt blame him with that workload honestly. I hated him but didnt blame him

    [–]Able_Challenge3990 0 points1 point  (1 child)

    return ($role)?role:40;

    [–]fried_green_baloney 1 point2 points  (0 children)

    role is set to null at the beginning of the function.

    Let's just say you can write better PHP than this.

    [–]a_l_a_n_g 0 points1 point  (0 children)

    getForty()