Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125067 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id EF3FD1A00BD for ; Tue, 20 Aug 2024 12:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724155857; bh=spIH2A8UkgOiHIGeUZnLocGqQLEcaItjNEvxwYsz2ws=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Xp0wCFIQD0qemfDxTDNzN6GbPm/GFol78dHDTylqnFGtxiX+qD1n+4/P3pX1l1SfX Sf/Ia08G1Uexko3LznS6uuCroO85J1eyuLZYIYMACbO9TwECgjrAYUE37VYbygBYo4 Lu3VJyIWTUMu3G6eoM0iwG5tPk/AcDJJrYlL2sXD8EtQt7afwZJWSLU08JOk41R0pS luzLiOwBWVTGBlq/ta6b7tZGTIPO9kv1y9/SHKieI1/fr+gy7BdaJ0eW3YdOJNQV3i xiWp+uZX9Fl6MUizs5h9o7mnGNRoh7et8wNUXjA1l2uZ/Z2TnGFlCVmsWNLfuDacch l8RWIDYsQ9i8w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57CF9180034 for ; Tue, 20 Aug 2024 12:10:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 20 Aug 2024 12:10:52 +0000 (UTC) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a7a94478a4eso1111092466b.1 for ; Tue, 20 Aug 2024 05:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724155742; x=1724760542; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=spIH2A8UkgOiHIGeUZnLocGqQLEcaItjNEvxwYsz2ws=; b=EBpFQdNtoS3WsgkNNdrWaOEfxT0OTfkAvt3rwVo12X72x5I6xu7xftY/oFNI4BfyY+ Z2WvKi+QMx+5gXuIuye7oXoquTA7oWzXmX0CYWzlLAqb6vfoOH5rIhhr1tYl9pSTUIOV uHo+b0adRdsChYwOt3pxYUz9izeNJzxJ/0RJ4UQBDPnEf/uwDGkJHjFCjD49LUL+lHX6 ciI8YMuDdOuzverbgW1OM8wsjkw4pvYifQUPH7WVqfY4QQqbduQswnrd5gE98MVNmGMb y23w2YS/8mUxM5vU6Yjp4V6TF00mipdqs3QRcetVsiAAoB2i4FTfFci7PEgaXXbmI1WY pA9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724155742; x=1724760542; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=spIH2A8UkgOiHIGeUZnLocGqQLEcaItjNEvxwYsz2ws=; b=Ax6aUA7BCmYh5ttWhxOPiFRuExhRK1ijdM1s0+qqTWmVpws0j96N/X315MfoPSeQ7z uNHD4fTNNVQJpopfumB+0oCaxny7TRv8JxxgKG4Miio3uAfCB0gYjnZMADnuAun4AupR /AbnCrJZ6w9m/t6/rpnSRawoY9bCFhuYuql2mrk/8aF0RO+snUwrk8F3DlcuaWegV3/B fiKTfSqH6hFtMzq4kRftyHeXtuKwzoDRxn1SMRIBKyof8sTG/kPPUOyCi+oiqn+skbFV Zv1C1WHKJAfSkXRaQXxIF32xLAW+TJ6KQWik3iU0WSs2nLkEm6wKBzWro1qF/Jhg6CmU x4bw== X-Gm-Message-State: AOJu0YwtN4KWrhBgZdBVu7aDB/LDUHAECCKRpgFNuk3iBoZIgJi9nVPg lVfs+Ehqz0L7B/pEiEe0R1U7FIFL99b6ktfzq4JAvYhzWMNpE4YBVf0LJabd7/14gNL21AuKM0t /8QEAmrmhWis1R13fYLy+Gw4dOuULOo9a X-Google-Smtp-Source: AGHT+IHbqfQL/fEEq0YI1tnE0uJyQa0yA4dGApGUiMerNgTO2EzPMFJAbs4c5aLBwf52bsCISyH9NxRtp9NhPlAavkg= X-Received: by 2002:a17:907:7f15:b0:a80:b016:2525 with SMTP id a640c23a62f3a-a8643f734camr206954466b.8.1724155741999; Tue, 20 Aug 2024 05:09:01 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> In-Reply-To: Date: Tue, 20 Aug 2024 14:08:50 +0200 Message-ID: Subject: Re: [PHP-DEV] State of Generics and Collections To: Rob Landers Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Rob, On Mon, Aug 19, 2024 at 7:51=E2=80=AFPM Rob Landers wro= te: > > Invariance would make arrays very difficult to adopt, as a library can = not start type hinting generic arrays without breaking user code, and users= can not pass generic arrays to libraries until they start using generic ar= rays type declarations. > > This seems like a strawman argument, to a degree. In other words, it seem= s like you could combine static arrays and fluid arrays to accomplish what = you are seeking to do. In other words, use static arrays but allow casting = to treat it as "fluid." > > In other words, simply cast to get your example to compile: > > function f(array $a) {} > function g(array $a) {} > > $a =3D (array) [1]; // array unless cast > > f($a); // ok > g((array)$a); // ok > > And the other way: > > function f(array $a) {} > function g(array $a) {} > > $a =3D [1]; > > f((array)$a); // ok, type check done during cast > g($a); // ok There is potential for breaking changes in both of your examples: If f() is a library function that used to be declared as `f(array $a)`, then changing its declaration to `f(array $a)` is a breaking change in the Static Arrays flavour, as it would break library users until they change their code to add casts. Similarly, the following code would break (when calling g()) if h() was changed to return an array: function h(): array {} function g(array $a); $a =3D h(); g($a); Casting would allow users to pass generic arrays to libraries that don't support generics yet, but that's expensive as it requires a copy. Best Regards, Arnaud