Hacker News new | ask | show | jobs
by kijin 2401 days ago
Mixing named parameters with unnamed ones is ripe for confusion. The syntax is also going to get rather ugly now that parameters can be typed, too. If I need to pass around more than 3-4 parameters and their names/types matter a lot, I think I'll just define a class with clearly named properties and pass around an instance of it.

I'd love to have a shorter object syntax, too. For the time being, I'll make do with

    $city = (object)['name' => 'Berlin', 'population' => 3748000];
which is a little verbose but gets the job done.
1 comments

I think there is an rfc for object initialization similar to C#:

    $city = new City {name: 'Berlin, population: 374800};
Edit: found it (and it uses = instead of :) https://wiki.php.net/rfc/object-initializer