Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123892 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 909AC1AD8ED for ; Wed, 26 Jun 2024 20:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719435525; bh=3CN1D0qB689LPdn4nyeJCRE1rrgLQJRjxkuS9xeeBZA=; h=In-Reply-To:References:Date:From:To:Subject:From; b=AWr0Yr40avpZbgfQhpyqURTNrDwiXdbFYa5009x/+6I8ih4OApvMqB1tsTVGCOAdC cboVihMwVGoBjEhXq8Gm334kWI6zU4F6/LRaGZ3OHmqh/8GSrqtugheJBd/1EEiPK+ aaE8eOPGWKiewxmMdrxUoYQT9zAz8Q7P8OlHjckwqEN/th68IK/gWSaE57TgL740p7 g6zH8mnItWF/BYzhGN/4lI0fDRBHoyQokNS1yG+/PH7/0r53p18yqWF6Xr5BEKttpW LNNGAEL11eXOEdLl6V82jGVANjGmuuvRJQRYL8To3x7XiYoylDo0rCezzT7IiaXoGS pzTQzX7hyKXsg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 289971810C7 for ; Wed, 26 Jun 2024 20:58:43 +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=4.0 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_NONE,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_SOFTFAIL,T_KAM_HTML_FONT_INVALID, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (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 ; Wed, 26 Jun 2024 20:58:40 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.west.internal (Postfix) with ESMTP id E97BE1C00092 for ; Wed, 26 Jun 2024 16:57:21 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute3.internal (MEProxy); Wed, 26 Jun 2024 16:57:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719435441; x=1719521841; bh=Q/88SqT1KDFpkB7HNgtNi3Ex7PBm n364Ze6nl+8LhC8=; b=pGDyQQybBmu8gYHtyYEfcsKfESj7rfVprIsrgt+fRYEQ uKPIxyxBa3MAlaDqrl7Cn7EUE1KpAnjZevTnNHO8Oy1RAcYNz5hPweSF17GoLmfE X9W9fY/rveScxwC/95NtFzMtcoqoZm5gCl9wbguzGe18IyHeKfPwhFFAocN+nk6T Lx5uCUQApqqhzg5ql8W22J0SKArx2M6fXYmuN3Zsl54zCnZ5NevAFTTIcLr4WPju P8g1SkvYj84xtVu380h0AigrMezZ7BO1Yk9cNaR/o3bBJrpoaTfsTONMSEHlYCxo RKRFX79H8jDFhDq1uq4Oj8PNxx3jm3x+HxAWgETIEg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddvgdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesrgdtreerreertdenucfhrhhomhepfdevrghs phgvrhcunfgrnhhgvghmvghijhgvrhdfuceolhgrnhhgvghmvghijhgvrhesphhhphdrnh gvtheqnecuggftrfgrthhtvghrnhepgfelhfdtueektdetfeeuvdetvdektdevfeevleev ieehgfdvhfehtedvffeitefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrnhhgvghmvghijhgvrhesphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id4f946ef:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4650F1700093; Wed, 26 Jun 2024 16:57:21 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <71dc8137-ded0-41dc-bc9b-32dde12f9170@app.fastmail.com> In-Reply-To: <6D0733B2-A1D1-45EC-B93E-029B1616A22F@miles.systems> References: <6D0733B2-A1D1-45EC-B93E-029B1616A22F@miles.systems> Date: Wed, 26 Jun 2024 22:56:08 +0200 To: "php internals" Subject: Re: [PHP-DEV] [Initial Feedback] Typed Arrays Content-Type: multipart/alternative; boundary=89e337023a964c749b3bea3bd83c9726 From: langemeijer@php.net ("Casper Langemeijer") --89e337023a964c749b3bea3bd83c9726 Content-Type: text/plain On Wed, Jun 26, 2024, at 21:59, Richard Miles wrote: > I think we should have typed arrays in PHP. Yes! I cannot stand sitting through conference talks on 'generics' that only talk about 'collections'. This could be solved if we had typed arrays. If anything we would get better talks on Generics. :-) Arrays of a type is one of the last cases where I need docblocks to tell my editor about the types. In my opinion, even if we would have some implementation of generics, having typed arrays with a simple syntax would be awesome. A syntax suggestion: $array = stdClass[]; class A { public stdClass[] $array; } Adding an invalid array member should throw TypeError. I know there are way more edge-case situations to think of (for example: if class B extends A, $b is of type B[], but holds only A's, can $b be assigned as value of public A[] $a ?) > Generics or bust. I do not understand the reasoning behind that. Is it because we really want generics, but when the 95% use-case is solved we fear that there would not be enough momentum to get that? I'd love to have generics too, but a very simple array syntax would in my opinion still add a lot of value, even if we already had generics. --89e337023a964c749b3bea3bd83c9726 Content-Type: text/html Content-Transfer-Encoding: quoted-printable

= On Wed, Jun 26, 2024, at = 21:59, Richard Miles wrote:
 I think we should have typed arrays in PHP= . 

Yes! I cannot s= tand sitting through conference talks on 'generics' that only talk about= 'collections'. This could be solved if we had typed arrays. If anything= we would get better talks on Generics. :-)

Arrays of a type is one of the last cases where I need docblocks to tel= l my editor about the types.

In my opinion,= even if we would have some implementation of generics, having typed arr= ays with a simple syntax would be awesome.

= A syntax suggestion:

$array =3D stdClass[];
=
class A {
  public stdClass[] $array;
}

Adding an invalid array member should t= hrow TypeError.

I know there are way more edge-= case situations to think of (for example: if class B extends A, $b is of= type B[], but holds only A's, can $b be assigned as value of public A[]= $a ?)

 Gene= rics or bust.

I do not underst= and the reasoning behind that. Is it because we really want generics, bu= t when the 95% use-case is solved we fear that there would not be enough= momentum to get that? I'd love to have generics too, but a very simple = array syntax would in my opinion still add a lot of value, even if we al= ready had generics.

--89e337023a964c749b3bea3bd83c9726--