Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123884 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 E59021A009C for ; Wed, 26 Jun 2024 19:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719432033; bh=5yeKrrqzK1vaBRMrH1TTjPq+4K52NeN/WtgruVAI6pE=; h=From:Subject:Date:To:From; b=NfIeJSUhQUbbted+PBmI1/DDEGhhT18JYott1MZD0HLxCOhM+7dMY3tgxfhqvgtQO ctg7/O6J2r15psiZ/kPYq1eOvyCjF/YgKT6PCQtOU6zueNtXCpb/ghz+4AeWbLIpHX HgZw4DQ0ygXggTAkwRzOemK3LVfqbMpcCKHZmyDaerIRmBtvos/YB0lvZrdrXzC722 KuRIPCeuMSz/M1TTO3QkjNt5eU3YGMYTypLeq32QRmBI1az1WMQANrNFNleCV5QI1l +M8HJ1D1MKak23zFqPeXv8sbmcwhTOzqtGvE/Y2Ca9Hy8yfZyQq0WY3fTJjD3xwCtB TLxHAF1xReGMg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 80FE018055D for ; Wed, 26 Jun 2024 20:00:32 +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_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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 mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (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:00:31 +0000 (UTC) Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-3737dc4a669so28830135ab.0 for ; Wed, 26 Jun 2024 12:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=miles.systems; s=google; t=1719431953; x=1720036753; darn=lists.php.net; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=gOuYYHI/Twp8AzpF2r5AXtpM+ysSJUCCcOdL6XBDB0U=; b=SEYgMWqrVOe/+NHmZ4uS4OekWiSBcDktQEtyjJyKc9VelOTwX0Ifpn9JGJTm03UQhL V9/twG5o81XdYDlEGTlloj56KX3RQFY27TwUIAAsUIRR1tAYry7P8eROLMWNzyJLQi4U nvxSXfrOWrAr1hNOngrYQsd4ZHca3Xyt+4EizDQjexfdZ77ILbXCJqP1dI8PSqekVfsj qsmDLb3/KdUDxeU/prCXQ5hRCozlmKrNQrzRlFJwANRJzdF2nE1kMWLgTvujbSCRr40A nSw4WOx7TdYNT292sF5WmAy6fDbswiAqzEfs28Yp2A9ptYeGclWWPGqb2P9kaTj3zbV0 5bkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719431953; x=1720036753; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gOuYYHI/Twp8AzpF2r5AXtpM+ysSJUCCcOdL6XBDB0U=; b=eDE4hoIhiHpoGTgYENTyG2D0HVkPvCSI3RzalwVTBmQYkNDbPJnyADRn+1/2+wJKyj sYKvZpliddU4AvF64fZdLizJXw9qkJrIVWq0mNEW6YrPLQA25goKHLOTPoPVSJtJPQMX eAusnTL2H4qD3Feip/GcRInUj/xkVCW1iv6O/JXucfw93lj2Yq6uwRb4wXZVeFmQrbo2 UCxCcfD9jbeAdTW9zDRfBxMfmLnNX6DAk1Nscd26wiK5E7UQtzfZa1Bkx5oZ6LMaUSWS oZU9VlKOtp13KIDZgbc1n1O/s3qwRO8Txz8yqDXQHwppkBSSBOYifxYu1uZ1AUGtAFN0 uEYA== X-Gm-Message-State: AOJu0YxuzxgSY645Xdk2v/eh95k3V70qLq4wpRYqsUtlrWmBAbiZBYno UpCWgc8SDL8HxTJjly7FNf8l50/NgeFs2LjQHtOcjQG0UpbczQmtb7WbSJOwEHxlpta6ENmTDPO dE9v6C9S1IaTa7k4oLA1d0stzBCa2Z1isUMoIGS2l/KHklouclFAFEj/HCnQife4xtSZQGYPMWs sQ9uy0HCERvMh9a59+KPwlAySre+4fypSaauQYxPgR X-Google-Smtp-Source: AGHT+IGd/7lZpyU1a13NUR8n2cerBk0l5nvk0GSXUeCnnCqcEXz5dbxBCxMBXp/LpvRZudgnL/s9GA== X-Received: by 2002:a05:6e02:12cc:b0:376:148f:d6c6 with SMTP id e9e14a558f8ab-3763f6cd2b8mr151271715ab.24.1719431952990; Wed, 26 Jun 2024 12:59:12 -0700 (PDT) Received: from smtpclient.apple ([2601:283:4600:6770:1058:1c9c:6c8b:173a]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3762f3a6a76sm28435325ab.86.2024.06.26.12.59.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2024 12:59:12 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_E5842DD4-1AE2-464B-95A8-6BC167BECB12" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: [PHP-DEV] [Initial Feedback] Typed Arrays Message-ID: <6D0733B2-A1D1-45EC-B93E-029B1616A22F@miles.systems> Date: Wed, 26 Jun 2024 13:59:00 -0600 To: php internals X-Mailer: Apple Mail (2.3774.600.62) From: richard@miles.systems (Richard Miles) --Apple-Mail=_E5842DD4-1AE2-464B-95A8-6BC167BECB12 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Howdy people,=20 The pattern-matching RFC inspired me to write this. I have not done any = work for this yet; just looking for initial feedback. I think we should = have typed arrays in PHP. I propose adding the class = SplTypeDefinedArray. A few considerations: A new syntax allowing Array = interfaces will be needed. Functions should be allowed to return array = interface types. How do we pass the interfaces to the constructor? Do we = stick to traditional syntax, creating the object with new, or do we = support a new array definition syntax?=20 interface iArrayA ['a' =3D> string ] interface iArrayB implements iArrayA ['b' =3D> string, 'c' =3D> ?string = ] $a =3D new SplTypeDefinedArray(iArrayB, [ // iArrayB::class is invalid=20= 'a' =3D> 'hello', 'b' =3D> 'world' ]); // or=20 $a : iArrayB =3D [ // this would implicitly initialize = SplTypeDefinedArray 'a' =3D> 'hello', 'b' =3D> 'world' ]; If a typed array tries to define an index that does not exist it will = throw a `RuntimeException: Index invalid`, which is consistant with the = current implentation of `SplFixedArray`; If a type is nullable then it = is not required to exist during construction. Standard-type operators should be available.=20 $a : iArrayA & iArrayB =3D [ // throws a RuntimeException since B is = required in iArrayB 'a' =3D> 'fail' ]; $a : iArrayA | iArrayB =3D [ 'a' =3D> 'profit' ]; $a : iArrayA &| iArrayB =3D [ // throws a RuntimeException since c does = not exist in iArrayA and b is required in iArrayB 'a' =3D> 'fail' 'c' =3D> '' ]; I'm not sure what the best data structure would be. Rob Landers = suggested a circular buffer in the pattern-matching email thread, but = I'm open to anything.=20 Best, Richard Miles --Apple-Mail=_E5842DD4-1AE2-464B-95A8-6BC167BECB12 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Howdy = people, 

The pattern-matching RFC = inspired me to write this. I have not done any work for this yet; just = looking for initial feedback. I think we should have typed arrays in = PHP. I propose adding the class SplTypeDefinedArray. A few = considerations: A new syntax allowing Array interfaces will be needed. = Functions should be allowed to return array interface types. How do we = pass the interfaces to the constructor? Do we stick to traditional = syntax, creating the object with new, or do we support a new array = definition = syntax? 


interface iArrayA = ['a' =3D> string ]
interface iArrayB implements iArrayA = ['b' =3D> string, 'c' =3D> ?string ]

$a =3D= new SplTypeDefinedArray(iArrayB, [  // iArrayB::class is = invalid 
  'a' =3D> 'hello',
  'b' = =3D> 'world'
]);

// = or 

$a : iArrayB =3D [  // this would = implicitly initialize SplTypeDefinedArray
  'a' =3D> = 'hello',
  'b' =3D> = 'world'
];


If a typed = array tries to define an index that does not exist it will throw a = `RuntimeException: Index invalid`, which is consistant with the current = implentation of `SplFixedArray`; If a type is nullable then it is not = required to exist during = construction.

Standard-type operators should be = available. 

$a : iArrayA & iArrayB =3D = [  // throws a RuntimeException since B is required in = iArrayB
  'a' =3D> = 'fail'
];

$a : iArrayA | iArrayB =3D = [
  'a' =3D> = 'profit'
];

$a : iArrayA &| = iArrayB =3D [  // throws a RuntimeException since c does not exist = in iArrayA and b is required in iArrayB
  'a' =3D> = 'fail'
  'c' =3D> = ''
];


I'm not sure = what the best data structure would be. Rob Landers suggested a circular = buffer in the pattern-matching email thread, but I'm open to = anything. 

Best,

Richard = Miles

= --Apple-Mail=_E5842DD4-1AE2-464B-95A8-6BC167BECB12--