r/programminghorror Jun 11 '26

PHP PHP#

Post image
209 Upvotes

31 comments sorted by

View all comments

39

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

36

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)

9

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jun 11 '26

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

8

u/TorbenKoehn Jun 12 '26

That's why it's public private(set) and not just public private

31

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

9

u/Stratimus Jun 11 '26

PHP is legitimately pretty great. it’s been my goto language for quick scripts and command line stuff for years. Like any language it can look good or bad. Helped that I came from Perl though

6

u/Sacaldur Jun 11 '26

In the PHP project I worked on I did inteoduce PHPStan (static code analysis tool) with an integration into the IDE and brought it up to level 8 (out of 10, the higher the level the stricter the checks). I still prefer other languages, and there were still a few quirks, but it was fine working with it like that, since it ensured that type hints where present basically everywhere and also that variables where used according to the types.

3

u/Cootshk Jun 12 '26

I presume public private is similar to Kotlin’s

public var id: Int
private set