Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123730 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 96C2B1A009C for ; Fri, 21 Jun 2024 13:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718978332; bh=cSlRix6vIIVkRhvjCIfnugGROm93vR/+t8RLTXlxflc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Efl/Y1OrgXVsrMLWtHXfZFvttyqXBV3bMKi4e8GZID17Xj3vOh3exZnfH/n3lZtUw qy3k1cv7Tl7TIKw3xi1Vj+az4PNSWKKISEBfHxO+wPhqLbMfkOrtULYZcUfSyoBoZh JK2xYfur9mLcDDkrwf32Le1+gUayjHNAHTIy4EHiX5BPgQHyTcxmr4H8CKFEcNHapG yd7WedHfXVFTS96AtD4TNZ75qfYe4M8WYp1K1uGzrBfKEp1gsLc9JBpmPlmQsZCqQq RzJoQ+BAmSHN1TFruKegTktCmfBad/Nlc5f7kOGED4HBlgYVcK36NTIfOnxUa+D6d5 G0ZWYQ633qUIA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 228C718037E for ; Fri, 21 Jun 2024 13:58:52 +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_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-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 ; Fri, 21 Jun 2024 13:58:51 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-52caebc6137so2186889e87.0 for ; Fri, 21 Jun 2024 06:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718978256; x=1719583056; 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=SIP9Wapcve3AZWNB/JjxzedZAd2e4nQOMz+aTyO0J3Y=; b=jvVD5TdVUAhEQH3xfMcAcbJUp95FhD+MFSBHzqTP160mq+IedBFLLwNrlzOPvK222S S1TtwRUqQ55w+/jAUnKg2QaGlIkgpc2nxV8ce72K/uQKN3QxpAXA088QYJ21mTBSLHDI ZRXiHrH3UO7klRp39v1aJW3KgeQm/q602tVZV+pOtFhy/lbKZTE5LmIyKEkSe94X9J++ qwEESIfahx/wPbOudOZnesR1D25PcHbaHatQKjQyMlFrz+jaqmv6zDB3nyQjocgE1hNg WXK2yXLcZpoG5yCA83V9+yzlaxnH4f+ps1HIa9+xqift8QQlYaHV4haPav0Cp+OBgr9O KiGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718978256; x=1719583056; 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=SIP9Wapcve3AZWNB/JjxzedZAd2e4nQOMz+aTyO0J3Y=; b=bvEKlEczYF5+zidb7j8gfOUZhaTw2MHoTowZAvLOpu6/QKBv6Pfn+Zei15J/NMPYVT XLgECIszd4ppF2Lq3T67fWbvNur0Jlm/shjyd8IpBQxhnx1SfgMLO4RSqMiL5pY+6TfP LQZsMU7eCEveHZDtNF3OUHFOLHZjCRSf6jkEpsLETZWqnG0LuvAaQvuIG2miDbxkBLyH C/eT0+pZY+uYN/15vHuQ5q3TeaAc+ZK32JBZHkW4Ueowib1qu2kBNoU7k5j2mRvA8p/s ym+pJ/8sVt4DyE8BKA0HELxJfue4dPuvu2sjk2MaYDM5Zt4pw6tYsQP8yyanBsoFaMWf lSWQ== X-Gm-Message-State: AOJu0YyeNNUIX8CCvAvoB9qon6IkoZuDqpquQJRqwXLOzdrXq0ZIBlWA XqdVfm+hXB1g2xXOMxbBzJmxVS0nJPaYYx6FbCn7emUkyzbSMis/urd/UHNcEyOqDe+WtLHqxVi j4WTDFgEtPDctMZbY9ZynZF/WLsHmImgqid8= X-Google-Smtp-Source: AGHT+IHxU9wzYziZRLqVX4O1M1RYPOL1rmPxSWDnGQH2Ar9dONNuxLnX64Zjs93LAGHRDXDTDQJTwUUyO7LVEgm2jFo= X-Received: by 2002:ac2:4181:0:b0:52c:c0ed:b006 with SMTP id 2adb3069b0e04-52ccaa92843mr4671495e87.51.1718978255310; Fri, 21 Jun 2024 06:57:35 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <9d28c9tOCChpWUcP1SFiFwtf2-w2XAtDzHsmM73myA7zfBsn7TxxEqs-VCnxRAgZjsk2TxS55owmM8wSLgBQL8LgeQLntUQ9toeLMkjTVx4=@gpb.moe> <673a1803-83c4-44b4-bd73-4ba61e83412e@app.fastmail.com> <350c1531-9bcf-4e7c-824b-8d9904b9e48e@rwec.co.uk> <914cde73-3e53-44a8-94ff-bcf34000cc0c@processus.org> In-Reply-To: <914cde73-3e53-44a8-94ff-bcf34000cc0c@processus.org> Date: Fri, 21 Jun 2024 15:57:22 +0200 Message-ID: Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" To: Pierre Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Fri, Jun 21, 2024 at 3:01=E2=80=AFPM Pierre w= rote: > > Le 21/06/2024 =C3=A0 14:27, Robert Landers a =C3=A9crit : > > This is why I wanted to work on "as" part of the pattern matching. It > isn't clear what will happen with the actual pattern matching RFC > (yet), but being able to do: > > some_function_expecting_int($_GET['foo'] as ?int); > > And how about: > > some_function_expecting_int(\intval($_GET['foo'])); > > And moreover, I'd write something like this, but: > > function validate_int(mixed $value): int { > if (null =3D=3D=3D $value || '' =3D=3D=3D $value) { > return null; > } > if (\is_int($value)) { > return $value; > } > if (\is_string($value) && \ctype_digit($value)) { > return \intval($value); > } > throw new \InvalidArgumentException("What what!"); > } > > some_function_expecting_int(validate_int($_GET['foo'] ?? null)); > > But the example might be erroneous, I see your point, nevertheless making= coercion explicit doesn't seem really relevant to me, the one point I like= in your syntax would be null handling. > > -- > > Pierre Or... you could just turn off strict types instead of reinventing coercion that isn't nearly as well documented as the built-in coercion. Robert Landers Software Engineer Utrecht NL