Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119494 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55891 invoked from network); 8 Feb 2023 17:23:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Feb 2023 17:23:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C01FE180507 for ; Wed, 8 Feb 2023 09:23:04 -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-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (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 09:23:04 -0800 (PST) Received: by mail-oi1-f179.google.com with SMTP id n132so1605410oih.7 for ; Wed, 08 Feb 2023 09:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=R137oMilbTcQcCQ69JeDion0CSo3gauZ/w0Ihx4AS5o=; b=qVkVr4XD9WbNKKNYq2rfsKpuyBZPTvQ5rU+vUsqu2yU+Ezh7UFV2sbrm5x5cXgvre9 xIqqfIYzpAc5sd/PzjCnfE+Br/zyes4ydG9l2LeHi03PXcqrQFqtdeTNPIT9nZ3MIP8b uZdqse6azkK7ZuYiVWfnf+2SdikIoImHc/mZZKGjT07cVB+uCPzvOXTofqRxTVO37YXf Sp9bPlYQJkPSaOKDwbwVKqiSKbtlz67RBB3M4DmqxBvwVv/Dj0+eGKN3+EHsIePPIu45 ddRmepZ+A6U7sHOEV5PC67itXG4eUqbJ9o5LYzlIkSbtUKv9AbPrNY9/9Jlj5GHCHcBE I4Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=R137oMilbTcQcCQ69JeDion0CSo3gauZ/w0Ihx4AS5o=; b=Cu4UNCGXi5Q1FmKbjizcVlZZI59dOP/XqBNrJNQM0Zmykz/BDa6lC5kIhpfAtRiV7p xf3smPSLO4wdyqZRVctF9DvNFmUasT0uzG/bnjencdpO3s8KDC1VxyKLGw7CQtPITMXX eC9S8BEIY2tj2VETf82SybHaUlDnVKknYz2yiBOULnqJea4Zfo9SsBb8p/PPGd2aj3PT ENPZpFXMtw2dC0jdekHIECV7+dkZI8OnCrhEvJy3ur+jvhlJ3JHUs7QzykvDXR5q3N3C 8VQE3AeVKgzl2KLGNFAceyCNEhtwHv02EN1SOOAOUBR0Peb0KY4gfgKI4HPvFtgZpQ80 58vw== X-Gm-Message-State: AO0yUKVvQRTf7cIR/hy7trenONdc2GXovgnbXczXY9LNWgX3OrXiUEqq 5dasDNxTlWh+VsrkSou7obPLeKrqrwLtKiXZyDvy/xYVTL0= X-Google-Smtp-Source: AK7set8WFcAAeHtZ2vG3RSX3dppD7CFX65rt5PXQtELfWYBtEMv281NCBsUrNwGV5C5Lux/Y9zJaYrfdZEZo+UgeKiY= X-Received: by 2002:aca:bb82:0:b0:367:bf22:81df with SMTP id l124-20020acabb82000000b00367bf2281dfmr228097oif.31.1675876983349; Wed, 08 Feb 2023 09:23: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:22:52 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="00000000000047a8c805f433841c" Subject: Re: [PHP-DEV] RFC Proposal - Types for Inline Variables From: wendelladriel.ti@gmail.com (Wendell Adriel) --00000000000047a8c805f433841c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello everyone. I created the Draft for this RFC: https://wiki.php.net/rfc/local_variable_types I'd love to hear your thoughts on this before proceeding further. If anything should be changed or updated just let me know. I'll be happy to help with anything related to this. *---* *Best Regards,* *Wendell Adriel.* *Software Engineer **| Investor | Amateur Photographer | Musician | INFP* *https://wendelladriel.com * Em qua., 8 de fev. de 2023 =C3=A0s 15:54, Alexandru P=C4=83tr=C4=83nescu < drealecs@gmail.com> escreveu: > 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 > --00000000000047a8c805f433841c--