News for hackers. Stuff that matters.
Re:Named arguments are coming in PHP 8 by raziel2p on Monday July 27, 2020 @03:35AM (#23962955)
With a dictionary (array in PHP) you lose strict typing and it's possible for the person constructing it to make a typo and it won't cause an error, the called function will just think an optional argument was left out.

Writing and maintaining parameter classes is just tedious.

Re:Named arguments are coming in PHP 8 by wonderlg on Monday July 27, 2020 @09:05AM (#23964671)
Typescript can do it, so why not add the same feature to PHP as well?

As a JS/TS developer, all I see is avoiding two characters: {}, everything else is possible in JavaScript and well-typed in TypeScript.

PHP 8

    save(
      value: 3
    )
JS 1

    save({
      value: 3
    })
Re:Named arguments are coming in PHP 8 by duckerude on Monday July 27, 2020 @11:43AM (#23966169)
PHP's strict typing is only enforced at runtime, and because of that, its type system is very simple, unlike Typescript's. You can enforce that a variable is an array, but not that it's an array of ints, let alone that it's an array with certain types under certain keys.

Although there is external tooling that uses static analysis for such more complicated types.

Re:Named arguments are coming in PHP 8 by xellisx on Tuesday July 28, 2020 @09:53PM (#23982740)
We really need structs in PHP. I drew up a draft, but didn't get very far with it. https://github.com/ellisgl/PHP-RFC-Struct-Data-Type