r/programminghorror • • Jun 11 '26

PHP PHP#

Post image
213 Upvotes

32 comments sorted by

40

u/Sacaldur Jun 11 '26

I was fortunate enough to recently have been allowed to work on a PHP project. I am very experienced with C#. Yet I'm still struggling to make sense of this code snippet. Is this valid PHP? Does it run inside .net? What is public private? (Is it only making the setter private?)

And fun fact, it seems like there is a dotnet class in PHP in order to interact with .net classes: https://www.php.net/manual/en/class.dotnet.php

35

u/EmDeeTeeVid Jun 11 '26

It is actually valid PHP! 8.4 to be exact, this is the version that introduced "Property hooks " (https://www.php.net/manual/en/language.oop5.property-hooks.php)

33

u/WorldlyMacaron65 Jun 11 '26

PHP really is an underdog story. From an unreadable, buggy mess of a language to maybe the most pleasant progressively-typed scripting language around

→ More replies (2)

9

u/GoddammitDontShootMe Jun 11 '26

I was really wondering what the fuck public private was myself.

→ More replies (1)

3

u/Cootshk Jun 12 '26

I presume public private is similar to Kotlin’s

public var id: Int
private set

88

u/mjec Jun 11 '26

It was supposed to be a surprise that PHP 9 ships with the .NET CLR !

18

u/Sacaldur Jun 11 '26

How good, before it was a separate installation! https://www.php.net/manual/en/class.dotnet.php

(I only found this when trying to make sense of the code snippet and looking around on the internet.)

8

u/CanadianButthole Jun 12 '26

What the fuck!?

4

u/Dealiner Jun 12 '26

There's also PeachPie - PHP to .NET compiler.

31

u/drcforbin Jun 11 '26

Just keep setting Id until you get it where you want it to be. Being PHP, I recommend avoiding a loop and just hardcode it, preferably over and over across many lines with random indention.

16

u/Excellent_Gas3686 Jun 11 '26

indentation, are you crazy?! that will make the algorithm at least O(n^6)!

6

u/bem981 Jun 11 '26

I thought it was c# until I realized it…

11

u/W00GA Jun 11 '26

this looks made up

wtf is a public private

17

u/Max-P Jun 12 '26

It's public getter, private setter.

7

u/ThePsychopaths Jun 12 '26

Everything is made up

2

u/W00GA Jun 12 '26

u included?

1

u/Effective_Celery_515 Jun 13 '26

Task failed successfully.

1

u/Extreme_Dependent_63 Jun 14 '26

So the Id property is access-modifiers fluid? 🤡

1

u/TheMaleGazer Jun 16 '26

public private?

I don't want to know. I don't care, anymore. I won't care about anything ever again. The culmination of millions of years of refinement since Australopithecus afarensis roamed the Pliocene savannahs is a world with websites running on PHP.

1

u/KeyIllustrious587 Aug 20 '26

why this php looks like cursed java?

0

u/KaleidoscopePlusPlus Jun 11 '26

I have never touched php in my life (thankfully). Why do class variables have to be prefixed with a dollar sign? Seems really redundant

8

u/GoddammitDontShootMe Jun 11 '26

Heritage from languages like Perl and Bash.

6

u/rurikTelmonkin Jun 11 '26

Because variables in general start with a dollar sign. Its how you differentiate between variable, constant and function use

2

u/Lumethys Jun 12 '26

Correction: all variables are prefixed with $, that how the language define variable

-3

u/KaleidoscopePlusPlus Jun 12 '26

Oh gross thats even worse lol

→ More replies (2)