PHP 7.2 - Argument type declarations, Object return type declarations

Nu inteleg la ce ajuta “object” ca type hint/return type. Care ar fi nevoia? Ideal ii sa fie totul legat de o interfata, incat sa stii exact ce intra si ce iese. Imi scapa mie ceva caz?

1 Like

Well, n00bs will be noobs and pros will be pros no matter how many language constructs and frameworks the world throws at them.

1 Like

Posibil mai multe cauze, mai mici…

  1. uniformizare, poti folosi celelalte tipuri ca type hint / return type.
  2. https://wiki.php.net/rfc/union_types este Declined (si poate nu poti sa-ti declari propria interfata care sa fie implementata de clase, pachete din composer?)

Poti folosi php in stilul JS si sa dai direct o clasa/o functie la o functie daca are ca return object din cate am inteles.

Ceea ce mi se pare iarasi interesant e trailing commas permis si argon2.

Da, nici eu nu inteleg cum ar ajuta intr-un limbaj care vrea sa evolueze intr-un typed language o obfuscare de genul acesta a tipurilor.