Live data from Hacker News

PHP's Oddities

flowtwo.io

51–60 of 186 posts

Re: PHP's Oddities

#51
post #37

Earlier quoted context omitted.

> People seem to shy away from criticism. What actual criticism of PHP is anyone shying away from? PHP got bashed for such a long time, while simply nothing steps up to do what it does better . Something that, for example, is available on every webhost you can just throw files at, where all (meaningful) config and state can be in those files.

I used to really love the dead-simple ease PHP brought to server-side dynamic web stuff too. But when shared cpanel type hosting was orders of magnitude cheaper than anything else, that was a way bigger deal. Today you can deploy a node.js app (all the same “just a script” advantages of PHP) to a half dozen places for free, and for the next step up, a smallish instance at Hetzner, DigitalOcean or whatever, where you…

But I don't want to manage 3-4 files, I want to manage zero files. I don't want half a dozen hosts, I want hundreds of thousands. It's not about costs, I really mean the simplicity and pervasiveness. PHP apps that are simple (in that they don't require any "rare" modules to be enabled) can easily be written to not run in relative folder structures, you can move them around like .exe files if you will. Not "like moving an exe file and then just updating a few lines in this file over there", that is a completely different thing for me.

edit: Granted, I agree that if you want to do all sorts of things on the internet, maybe PHP is not the right choice. But for simple, dynamic web things that I want to just make and then run like this forever, that I can work on but don't have to? PHP and vanilla HTML and Javascript are where it's at for me, hands down. Everything else I know is either too new or seems to have constant churn or issues. That you hear nothing about PHP other than complaining it's "outdated" or whatever from the outside -- always "why are you using this?" never "why oh why am I using this?" -- is because it just hums along, IMO. I like it better than Python, and I kinda view it as in that class.

Re: PHP's Oddities

#52
post #46

Earlier quoted context omitted.

People absolutely have VERY strong opinions and voice them constantly. True of every language but especially php. Almost feel like it’s more acceptable to rant about php than to praise it

I attended a talk by Rasmus Lerdorf at a FOSS conference in 2006. It has been a long time, so I remember only a few things from the talk, but one thing I remember him talking about is how people love to complain about PHP, often on forums that are themselves written in PHP.

Did someone reply to him with this meme? https://knowyourmeme.com/memes/we-should-improve-society-som...

Re: PHP's Oddities

#53
I've been writing PHP for 20 years now. It's my bread and butter.

The one thing I really wish PHP would add is structurally typed objects. I really miss it when moving back and forth between PHP and TypeScript.

They could call them anonymous objects if they want to (that would be a more culturally correct analogue to anonymous classes).

Like, I wish it was possible to do

  {
    string $mystring = $myvar,
  }
and have it be equivalent to

  new class($myvar) {
    public function __construct(
      readonly public string $mystring,
    ) {}
  }
and then be able to typehint it like

  function ({ string $mystring } $myobj) {
    echo $myobj->mystring;
  }
and honestly, why not go all the way and allow type definitions/aliases, something like

  type myobj_type = { string $mystring };
That'd be great.

Re: PHP's Oddities

#54
post #31

Earlier quoted context omitted.

If I have an “array” and can do array[0] to get first item, but when I filter this array and array[0] throws an error, that’s super weird. What is the meaning of [] or what is an array even? The language forces me to understand how it is implemented under the hood. That’s exactly what the author says: leaky abstraction.

An “array” in PHP is an ordered map.

Isn't exactly their complaint? It's called an array, referred to consistently everywhere as an array, but it just ... isn't.

Re: PHP's Oddities

#56
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…

Have you tried Lua or one of its variants?

Re: PHP's Oddities

#58

I've been writing PHP for 20 years now. It's my bread and butter. The one thing I really wish PHP would add is structurally typed objects. I really miss it when moving back and forth between PHP and TypeScript. They could call them anonymous objects if they want to (that would be a more culturally correct analogue to anonymous classes). Like, I wish it was possible to do { string $mystring = $myvar, } and have it be…

You can do that. Of course, PHP's native types are quite limited, but a phpdoc syntax should work with static analysis tools. For instance:

    /** @psalm-type MyobjType = object{mystring: string} */

    /**
     * @param MyobjType $myobj
     */
    function (object $myobj): void

Here are some documentation and examples:

- For Psalm, see https://psalm.dev/docs/annotating_code/type_syntax/utility_t...

- For PHPstan, see https://phpstan.org/writing-php-code/phpdoc-types

It may work in your IDE (autocompletion, etc.) but there is no standard on this side. Some IDE have their own parsers, others use one of the LSPs for PHP.

Re: PHP's Oddities

#60

I've been writing PHP for 20 years now. It's my bread and butter. The one thing I really wish PHP would add is structurally typed objects. I really miss it when moving back and forth between PHP and TypeScript. They could call them anonymous objects if they want to (that would be a more culturally correct analogue to anonymous classes). Like, I wish it was possible to do { string $mystring = $myvar, } and have it be…

You can do that. Of course, PHP's native types are quite limited, but a phpdoc syntax should work with static analysis tools. For instance: /** @psalm-type MyobjType = object{mystring: string} */ /** * @param MyobjType $myobj */ function (object $myobj): void Here are some documentation and examples: - For Psalm, see https://psalm.dev/docs/annotating_code/type_syntax/utility_t... - For PHPstan, see https://phpstan.or…

Yeah, at the moment we use arrays as anonymous objects and phpdoc+phpstan to verify the types, but I want it in the language. PHP already supports intersection and union types, it really feels like just skipping the naming part and going all in on structural typing is not that far fetched by now.
Post reply on HN