Live data from Hacker News

PHP's Oddities

flowtwo.io

161–170 of 186 posts

Re: PHP's Oddities

#161

Earlier quoted context omitted.

That's exactly what I was expecting to read about upon seeing the article title. But apparently they deprecated and then changed(?!) the associativity in the past few years, which if anything just makes things even more confusing.

This changed 6 years ago in 8.0, a major version change. Once again showing how out of date peoples hate for PHP is

To be fair mine and a lot of people's reaction to getting bitten by this was completely avoiding ever using the ternary operator in PHP.

Re: PHP's Oddities

#162

Earlier quoted context omitted.

Lol to true. Who even uses twig or smarty anymore hesitantly raises hand

I have a client I've been working with for decades (because they're great people to work with), maintaining and improving their php code base that still uses Smarty templates. So I know and hate Smarty from first hand experience, and appreciate what a terrible idea Smarty is and why. I've also extensively used Zope and Plone, which attempt to give designers a "safe" set of capabilities and subset of Python which was…

[deleted]

Re: PHP's Oddities

#163

> This lax behaviour for property definitions makes writing code around them harder. Especially when you take into account that any object can have properties dynamically added to them: Doing so now raises a deprecation warning, unless you add #[AllowDynamicProperties], and PHP 9 will convert it to an error. I'm told this will simplify internals and unlock optimizations. Arrays are still fairly awful, but generics ma…

Not sure why a language that barely has a type system needs generics.

PHP has had a type system for over a decade now, including things like union and intersection types that are still not in Java. Most static checking still needs an external analyzer, but even without one, PHP does check subclasses and interface implementations for Liskov substitutability in a way that Python does not.

Re: PHP's Oddities

#165

Earlier quoted context omitted.

That's exactly what I was expecting to read about upon seeing the article title. But apparently they deprecated and then changed(?!) the associativity in the past few years, which if anything just makes things even more confusing.

This changed 6 years ago in 8.0, a major version change. Once again showing how out of date peoples hate for PHP is

So it became sane as soon as late 2020.

Re: PHP's Oddities

#167

if("0") {} being equivalent to if(false) {} still gives me nightmares even though I've stopped using PHP for at least 6 years now :)

In what context are you doing if("0")? People always have these obscure type comparison complaints, not just for PHP, and all I can think is why would you write that?

Something you'll see in real codebases is code that cares whether an input value is "empty", but it doesn't matter if it's null or an empty string. It's very easy to go for this:

    if ($input) {}
It'll work through every test case you try, and then someone enters a 0 into the field and it's also unexpectedly considered empty.

Re: PHP's Oddities

#168
post #166
post #88

Earlier quoted context omitted.

Maybe that’s because a site last updated 8 years ago is utterly irrelevant for, like, anything?

It’s not so irrelevant if your org is stuck on older versions of PHP.

Being stuck on versions of PHP published >= 8 years ago isn't a valid excuse anymore, with AI and static analysis tools available IMHO. And even if you really don't identify using CVE-ridden, unsupported, ancient software to handle customer data as a critical business risk and insist on riding the burning train instead - well, then you've lost all right to poke fun at the legacy PHP versions you're stuck on, because the pain is entirely self-inflicted by your org.

Re: PHP's Oddities

#169
post #9

After over two decades of working in PHP, I'm now working in Java. PHP is basically Java-lite. I am absolutely loving the compile-time safety of Java, but I dearly miss PHP's maps and arrays. In Java, the amount of verbosity for defining a map/list and operating on it is overwhelming. Modern PHP is great. Many powerful language features, excellent performance, great community and package ecosystem, and decent enough…

> If you really do need the first element, you can use array_first That probably needs an array_second too, doesn't it? Maybe array_second_from_last as well?

That's foolish. It would clearly be named `second_array_element`.
Post reply on HN