Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106843 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46158 invoked from network); 4 Sep 2019 10:14:30 -0000 Received: from unknown (HELO mail-qk1-f182.google.com) (209.85.222.182) by pb1.pair.com with SMTP; 4 Sep 2019 10:14:30 -0000 Received: by mail-qk1-f182.google.com with SMTP id g17so18734797qkk.8 for ; Wed, 04 Sep 2019 00:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=szW3lai102zBiTJiRHLGMjymdZzEVZrNCwPWUHEpqcg=; b=GbpY0E9C4kctCQ+KAgwOZnwd8zGouz57RTk0W2OhIc//iVFEU/q5OVIHCGWo1nQN+V FZhL4Ru+KXoDaZ2eqJQlLbR2LDv85jGvdjVPHyee4/nflpijdL7L4nZ4xKN2barQYYS2 2pGPgKYvXQ/AEwdZ98YiJzIIP4cwmH8zQRmHzcO8dZKk5Qu0C5SiKyAa1OZknNSuiVIR dHHjCDjUxMA4pSvT1s6nBxeohQRxK/m11kyTzeiHAc6alucuzB/JCVHDQwPaVbMj/aq8 kHyzlW7Z5VJTM0AE3p4ORQQ+k8tQJVhGWObCxp3xwvdCFIU+t93mWe4F5w1+O3YRRYQe CvPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=szW3lai102zBiTJiRHLGMjymdZzEVZrNCwPWUHEpqcg=; b=N9VN/F4p9XqlXcl5eZ1hgy6EseChlL8rGFiznFKuZ46rytQYZZj12WUn+zq7rgOnVk kqSxqfA+EhuUG8tKraAxkgi26YjxyDDJu1sYP+hqg07Q4/8OhlTVghB9YPr44VNLFQAt /ME/k5HEX8lX8eEdsC7OlauJaGZkTdLJQWBt4dkzF52o8auqENVMxcaHwZUB4LgOEx1w 5DTOB1wXCD63pHa6GNxX9ZslV9WASpMeBlrKX3JiEBkE+EvWg3qSarko/gyiIvxUk7qa CB9S2PO7jNR6ZZSWjp8zTmBHZ7Miuzq2nQo31KP4Kc0o5wQAQgbKg4LdVW6V9oUb1K3B YXzQ== X-Gm-Message-State: APjAAAVlz0euseZEdGLzHx72EIy1mtqcP6S1ijX6AG6nPi42Ej4rj+Xp X5Wz+7gHeMPDUd4WX3XAnMl2jb2VItw= X-Google-Smtp-Source: APXvYqxXkNoSDrB4/IznZcw7dsnthhvhIYvu/YP+JSZfD8Cnokd3orKMQGm2K5Y/X8DDTVy0sQ1aHw== X-Received: by 2002:a05:620a:b:: with SMTP id j11mr38602968qki.352.1567583300491; Wed, 04 Sep 2019 00:48:20 -0700 (PDT) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com. [209.85.160.171]) by smtp.googlemail.com with ESMTPSA id u15sm7722905qkk.17.2019.09.04.00.48.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 00:48:19 -0700 (PDT) Received: by mail-qt1-f171.google.com with SMTP id n7so23356268qtb.6 for ; Wed, 04 Sep 2019 00:48:18 -0700 (PDT) X-Received: by 2002:ac8:70d1:: with SMTP id g17mr3764567qtp.124.1567583298680; Wed, 04 Sep 2019 00:48:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Sep 2019 09:48:06 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Lynn Cc: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , Fwentish Aelondes , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000ac7db90591b56d3a" Subject: Re: [PHP-DEV] Silent Types From: andreas@dqxtech.net (Andreas Hennings) --000000000000ac7db90591b56d3a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable In some other languages the mixed type is called "variant". https://en.m.wikipedia.org/wiki/Variant_type I mostly remember it from VisualBasic. Lynn schrieb am Mi., 4. Sep. 2019, 09:22: > Hi, > > Would this warrant a having mixed types? By making every variable of type > "mixed" when no type is defined, regardless of what value it receives or = is > initialized with, this would make an opt-in system. This behavior would > cater developers who prefer only strict types, only dynamic types, and > those that want to type their code bit by bit without putting declares th= at > affect whole files. > > ``` > $foo =3D 'foo'; > // same as > mixed $oneHundred =3D 100; > // difference being: > // $foo is accepted when 'string' is typed in the signature > // $oneHundred is accepted when 'int' is typed in the signature > > // no longer mixed, only accepts their defined type as value > // and is accepted only as their defined type in signatures > string $foo =3D 'foo'; > int $oneHundred =3D 100; > > // does imply we might need custom type definitions in the future to not > have to work with mixed > typedef Stringable =3D string | MyToStringInterface; > Stringable $foo =3D (bool) rand(0, 1) ? 'foo' : new > MyStringableObject('foo'); > ``` > > Note that this behavior would require making some decisions whether or no= t > in the future this opt-in behavior should change when a default value is > given, such as with C# and type inference when declaring a variable, base= d > on its assigned value. > > Regards, > Lynn van der Berg > > On Wed, Sep 4, 2019 at 8:12 AM Micha=C5=82 Brzuchalski < > michal.brzuchalski@gmail.com> wrote: > > > =C5=9Br., 4 wrz 2019, 05:52 u=C5=BCytkownik Fwentish Aelondes > > napisa=C5=82: > > > > > Hello internals, > > > > > > Zeev's idea to bring peace to the galaxy seems like a good idea, but > > > impossible to implement in practice. > > > > > > But it got me thinking about how one might introduce static typing > > > into a dynamically typed language w/out breaking BC. > > > > > > And then I had this crazy idea: > > > > > > //int > > > $i =3D 0; > > > > > > //string > > > $c =3D 'c'; > > > > > > //float > > > $pi =3D 3.14; > > > > > > If static typing in php was *only* an opt-in kind-of-thing, would thi= s > > > work? Could the parser be built to identify 3 or 4 different keywords > > > in comments and give warnings or fatal errors for type conversions of > > > variables that have the type specified in the immediately preceding > > > comment? > > > > > > Just a (crazy) idea. > > > > > > ---- Fwentish > > > > > > IMO it's crazy idea and we should not change the way comments work > > especially inline comments which even aren't kept in opcache. > > > > I think better approach would be to put type in front of first variable > > declaration like: > > > > [type] $variable =3D $value; > > > > > > BR, > > -- > > Micha=C5=82 Brzuchalski > > > --000000000000ac7db90591b56d3a--