Live data from Hacker News

PHP 8.5

stitcher.io

161–170 of 197 posts

Re: PHP 8.5

#161

Earlier quoted context omitted.

I think PHP is way better now than it used to be. Learn PHP 8 and you are good to go.

Until two years later the same thing is said about PHP 9, 10, 11. Constant change is not good.

People also hate how _slowly_ Python moves and complained forever about that. They also complained forever during the many years of 5.x PHP releases that PHP was moving too slow. It was only after Facebook forked first the runtime (HHVM) and the language (Hacklang) and showed how fast and advanced PHP could be made that the PHP team started accelerating. Which I think has been a boon to the community. This is all given away for free as open-source after all.

Re: PHP 8.5

#162

Why is it that all these languages like PHP, but also typescript are becoming like impossible puzzles to read. I find these generics, types and other language features very often causing complex software architecture. I see so many collegues these days struggling in understanding codebases. You almost need a PHD brain to be a frontend web developer.

Counterpoint (from the same website): https://stitcher.io/blog/evolution-of-a-php-object

PHP 8.2 has this:

``` readonly class BlogData

{

    public function __construct(

        public string $title,

        public State $state,

        public ?DateTimeImmutable $publishedAt = null,

    ) {}
}

```

Whereas in php 5.6, to accomplish the same you need all this:

``` class BlogData { /* @var string / private $title;

    /** @var State */
    private $state;
    
    /** @var \DateTimeImmutable|null */
    private $publishedAt;
   
   /**
    * @param string $title 
    * @param State $state 
    * @param \DateTimeImmutable|null $publishedAt 
    */
    public function __construct(
        $title,
        $state,
        $publishedAt = null
    ) {
        $this->title = $title;
        $this->state = $state;
        $this->publishedAt = $publishedAt;
    }
    
    /**
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;    
    }
    
    /**
     * @return State 
     */
    public function getState() 
    {
        return $this->state;    
    }
    
    /**
     * @return \DateTimeImmutable|null 
     */
    public function getPublishedAt() 
    {
        return $this->publishedAt;    
    }
} ```

Re: PHP 8.5

#163
post #77

A lot of people are too proud to be associated with PHP. I am ready to admit that know nothing about the language except that a lot of people make cool things with it. My favourite PHP product at the moment is BookStack ( https://www.bookstackapp.com/ ), a really good wiki. I run an instance for my family and it's great. But there are loads of things. And I notice that many of the sites I like using...are built on we…

> My favourite PHP product at the moment is BookStack ( https://www.bookstackapp.com/ ), a really good wiki. Another wiki that uses php is Wikipedia. People like to shit on php but it powers some of the largest sites in the world. At the end of the day, programming language doesn't matter much. You can be a good programmer in any language and a bad programmer in any language.

It's flarum for me - https://flarum.org/

A really good forum software.

Re: PHP 8.5

#164
post #85

The pipe operator example omits the typical way you would write this code in any language: simply by introducing temporary variables or by shadowing. The url parse example is not being compared to the builtin parse_url function that is just as easy to use.

Parse_url isn't standards compliant, often fails with relative url's and most importantly only parses urls, not uris (with the exception of file://). I also find it's syntax clunkier than the new uri(), but that's just personal preference. The pipe operator is indeed just syntactical sugar (and the article links to another article specifically about it which does cover the case of temporary variables), but with the c…

parse_url() also had no generate_url() counterpart - sure, it could (sometimes) split a URL into its components, but there was no safe way to modify those components and glue them back into a string. The new URI class solves that.

Re: PHP 8.5

#166

Earlier quoted context omitted.

Precisely. PHP has tools for this too, but lack the syntax. Right now you need to to all typings in comments, and thats just as bad as jsdoc was in 2005. This could be the way PHP could go, they just need the lexer to handle types, and not do any runtime checking at all. But i guess that goes against what the php devs want, but it sounds so wasteful, to typecheck the same code time after time even if it passed some s…

The current amount of typechecking might be a net efficiency improvement AFAIK. It provides a hard runtime guarantee that variables are certain types while Python has to check whether something is supported at the last possible moment. But I don't know how much use the optimizer makes of that.

Python is not (usually) run like PHP. Python programs (like most other languages) "run", compared to PHP where you in 99% of all cases instead "execute". (run = the program is running for a long period of time, and execute = run/die immediately).

This subtle difference has huge implications. You could in theory have an "compile step" in. Python, but in PHP you really cant as the program is never "running".

Python built syntax for types / generics etc. Its actually a quite capable typesystem (im not a python developer, but use python on some occasions). Python then has tools for static typechecking that can be run outside execution.

This means that if python would do actual static typechecking on runtime it would be nothing more than wasted cpu cycles.

Thats why python opted for the syntax only, as its basically zero cost. In php land the typechecking is done on EVERY execution, even if the code was unused. (a void functions that has an int param, but gets passed an string, that just discards the parameter). Even worse, a type error thats not executed wont be caught by every execution.

In short PHP typesystem is just runtime checks for primitives / classes and wont catch errors where not executed. Its like the worst of both worlds.

Re: PHP 8.5

#167

Earlier quoted context omitted.

I often return some collection of types in an array eg [User, Config]. Right now my return type is just "array". To get this to work i need to build yet another wrapper class and all that, and thats just wasteful and totally unnecessary. A even more simpler example is An array of some sort of Item. I cant return array(Item), but i only can return an array.

What do you mean, "to get this to work"? It's a PHP array. It will return whatever you need it to. What is not working?

The parts thats not working is if i return a plain "array" i can then put whatever inside it. Its basically the same as "any" but wrapped inside an array.

Re: PHP 8.5

#168
post #151

Earlier quoted context omitted.

It's moot to the aforementioned point. Undefined behavior wasn't introduced as a new language "feature" between C89 and C23; it's existed the whole time. We're talking about specification deltas, not the entire corpus. But, if you want an answer to your question: You can learn to avoid undefined behavior in about 30 seconds . If you're purposefully fiddling with undefined behavior, it's because (ideally) you're A) an…

Before you could assume signed arithmetic overflow will be whatever the CPU does, or null pointer derefs will be trapped by the OS. That is pretty big difference from what can happen now, moved C away from that "portable assembler" moniker so very not moot. Even if it was never explicitly standardized. > You can learn to avoid undefined behavior in about 30 seconds. Source? I mean, if it's really that simple then som…

[flagged]

Re: PHP 8.5

#169

Earlier quoted context omitted.

C hasn’t changed all that much, and someone who coded in C99 would take about 30mins to catch up to a modern C23 codebase’s changes. Famously so, as conservatism to change is the main friction in the community for about two decades now. If you pull out examples of the earliest C, sure, it looks weird . But that C was already obsolete in 1989. Since then, it’s had a minor iteration (e.g. five-eight additions/modificat…

C, as a language, is very simple. Which leads to horribly complex and monsterous code, especially in large projects. The language makes even simple paradigms impossible to represent, forcing you, instead, to just remember what to do and then do that every time, forever.

I made no value judgement of the language. Simply an assessment of its simplicity. I’m glad you agree with that. Feel free to let the other commenters know, not me.

Re: PHP 8.5

#170
post #151

Earlier quoted context omitted.

Before you could assume signed arithmetic overflow will be whatever the CPU does, or null pointer derefs will be trapped by the OS. That is pretty big difference from what can happen now, moved C away from that "portable assembler" moniker so very not moot. Even if it was never explicitly standardized. > You can learn to avoid undefined behavior in about 30 seconds. Source? I mean, if it's really that simple then som…

[flagged]

Hey can you please not cross into personal attack? We're trying for something else here, and you can make your substantive points without that.

https://news.ycombinator.com/newsguidelines.html

Post reply on HN