Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119488 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44360 invoked from network); 8 Feb 2023 15:54:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Feb 2023 15:54:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 58950180507 for ; Wed, 8 Feb 2023 07:54:05 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 8 Feb 2023 07:54:04 -0800 (PST) Received: by mail-pg1-f175.google.com with SMTP id x10so1899440pgx.3 for ; Wed, 08 Feb 2023 07:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2dhjhRxez+5wAgcg/TC8CwMlaPFoBmR4853lMMWMj0U=; b=MBXBXla+WZL3vVJDX9lylxeQuPUn+mL1EDG0iFm7zY809S5EKjnsSWJ+y5YYkWlT60 PlobV9zAYs+kcrzffnTmXjK4H/fRBjonvw4/CD3QBCX7FbxLxu9+Xr5hruTE4WGV3XKz QwIpbc4R1jpT6xUubn1Z1gAfeQ9VKVCYQ+/spRfT2k22TqE4u1Cui+mJEfJDKGDZWsSp gdnTuWU7M+rdqkHUoNm/8R4tfT5eKMLwlJ2iFUXVgeI617AfKbkgu3rv4XYA9U6A9GTB bbj6J0hhKVlfji7XfFsKIihXrtRFIVIQ0YRNa/5MUa4ysWVqcQuNt/44vRH50GSCRk+r eZsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=2dhjhRxez+5wAgcg/TC8CwMlaPFoBmR4853lMMWMj0U=; b=PTy9k1uEOA+yG4N8AlgwRCDMkhr+YIqKtPIpXEEkzqcN77s+g9DeOoAvSlelPNuxuO 5dlfIjZrpQ2gyAnwhb8FBtgRRut6ecwuqBmvmqG2DU2Ua5TGW+ap5JWr+Y+8ruVB79X+ ZOcG8m4opPZzZnYfX6cqBKXCKrqFY8RXXcQI2RnL2Z6400FOM3d63jE8JWlF3NJN9KlB j6O0XfzIDjo63W9vXIuqkjavgRjGvQt/nRP/auYTp8SlR44QQ6ZEW29aCFD6eLR2cqaV pjMIsK03KHjAxJV301oukZ3dVGCsYHGN5zrYf1hgDwvm8QDou4yGS/9Cuk7XGOahTro1 EDxg== X-Gm-Message-State: AO0yUKW3efUWGtqKujQCgXCIiJxpPO+1opyBiqgScULrD4c8A7NRiwR4 CkOwaf7kihTRtgIP0uBMcPAtnO9rs5uiJjeQuyEWSFE+gRg= X-Google-Smtp-Source: AK7set8UMnHulKGU42Xov9oGpMgJc+lqKQp6icSTaq8P1jY/W1vu36RoF3oauCQqdDVrE+KaG/VXCWH51JiaJse2TME= X-Received: by 2002:a63:7f4d:0:b0:4fb:2d7e:998d with SMTP id p13-20020a637f4d000000b004fb2d7e998dmr683758pgn.123.1675871643468; Wed, 08 Feb 2023 07:54:03 -0800 (PST) MIME-Version: 1.0 References: <18627e9c82d.1185ba82a2669697.6762525826203739336@wendelladriel.com> <8c3fb742-4367-0e4a-b96e-142657ac902c@gmail.com> <5edaa45e-08ff-9529-3a1b-42f655a68497@gmail.com> In-Reply-To: Date: Wed, 8 Feb 2023 17:53:45 +0200 Message-ID: To: Mark Baker Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000ff8a2a05f432458e" Subject: Re: [PHP-DEV] RFC Proposal - Types for Inline Variables From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000ff8a2a05f432458e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 7, 2023 at 10:21 PM Mark Baker wrote: > On 07/02/2023 20:53, Olle H=C3=A4rstedt wrote: > > No not really. I'd expect it behave similar to function argument > > type-hinting in PHP, that is, runtime checks, but where the notation > > can be used by external tools. > > The big difference is that the current checking for function arguments > is only necessary when a function is called; but that checking for > local-scoped variables would be required on every assignment to a > variable, or operation that can change a variable value; and that > becomes more problematic with the potential need for union types. > > Hi Mark, I saw that you and Olle were discussing that type checking should be similar with functions typed parameters . But in reality, it should be implemented more like typed properties. Actually that's already possible with something like https://3v4l.org/T6GFS function &declare_int(int $value) { static $references =3D []; $valueWrapper =3D new class(5) { public function __construct(public int $value) { } }; $references[] =3D $valueWrapper; return $valueWrapper->value; } $intVariable =3D &declare_int(0); $intVariable =3D 42; // works $intVariable =3D 'test'; // fails Even the PHP_INT_MAX works (it fails). To give credit, I saw it discussed few years ago on twitter and here you can see a nice playground implementation: https://github.com/azjezz/typed/ I don't see a bug technical performance downside, other than the wrapper class references that you need to have a management for. I think an implementation in C would be not less performant than how properties types are checked. Regards, Alex --000000000000ff8a2a05f432458e--