Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106858 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63377 invoked from network); 4 Sep 2019 19:39:04 -0000 Received: from unknown (HELO mail-qt1-f174.google.com) (209.85.160.174) by pb1.pair.com with SMTP; 4 Sep 2019 19:39:04 -0000 Received: by mail-qt1-f174.google.com with SMTP id y26so25301079qto.4 for ; Wed, 04 Sep 2019 10:13:01 -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:content-transfer-encoding; bh=LuU5mW38P/HXmSxBZyKkFrkdUGx1xqwC8Cq0q+2P+R8=; b=QI6Nfl7dKvCUBWQyv1PkblHsoIbEkwyYa91syfVwuScO1HIO5ob6CAeWyYn2MdbLcm fb0qtMfQLTCFkfZ2XkfY5yDYU7H5jPp117D8lqMdiXnCMiBxhpQenjO/Smaw3vlEVuBg EF6h2bSdwTaaa3oDlWAZPRwDexdergKSUG8Cj0L51M3FbXi7avwe8/gUFwi23Neja763 PqXrDcRErF3ugp3D3UUut3I4ibhPNRHueBWhfSFC7nW1moTBOBfsSsW7FediI0U7WN/q wqyBb9I2co/h6wc7H9+qjvxZl1WjXyDWDyTU52MBzEcoUmj9D7yEdubCXtkg7IsFJvds CWAg== 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:content-transfer-encoding; bh=LuU5mW38P/HXmSxBZyKkFrkdUGx1xqwC8Cq0q+2P+R8=; b=boWuY9kIqXp+X9AbFznTeMHM5tkU3VSKWnYOp+jbs2dREz7c75DazURu2GtbVux5yq BV7h/1fqsFzs0jbfDM4XhrKeA4MiBTBzVh0b3HtY1wZZTuY4b72PZ60c+Pf5mR+nz+8Z HN5N6zpTv0POOOjiv6P1SmjV00MRvGOV13Mj53b6+ZkOyq0n+FyvHAQDkASUtlorFBkX cJ4RhLZkdqUM2wf+urQaz9Hw1R3okqbrus4hu3km5QebvlB9XAJYYOueTsjBXHL/0dek kaN5X0ERV0XKVL9A+Cxo+BcCbkMOLFyKUUBAXMQyVcJvCj715zAzRkgaMNDg5MUKzV9L KW1g== X-Gm-Message-State: APjAAAUyYDYEryUcZ6A1SzXBcCT0Fd0vYVRVnfAeTNZy5fehPlfYeQvI p+0HmlTvRt46v/gwxRmVNURszhHuOfw= X-Google-Smtp-Source: APXvYqzNWoUD+ulE/mQg8DV9yl+b6Mymu3knBUSRZ3nPSeEuRWhpPYtr4evB5w3rzoP5H3l2JnfoSw== X-Received: by 2002:ac8:7504:: with SMTP id u4mr39191511qtq.81.1567617180307; Wed, 04 Sep 2019 10:13:00 -0700 (PDT) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com. [209.85.160.178]) by smtp.googlemail.com with ESMTPSA id 56sm8832285qty.15.2019.09.04.10.12.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 10:12:59 -0700 (PDT) Received: by mail-qt1-f178.google.com with SMTP id a13so25270989qtj.1 for ; Wed, 04 Sep 2019 10:12:58 -0700 (PDT) X-Received: by 2002:a0c:b44a:: with SMTP id e10mr23430359qvf.172.1567617178164; Wed, 04 Sep 2019 10:12:58 -0700 (PDT) MIME-Version: 1.0 References: <41AF2CFB-BB90-40B6-AB21-2710E46CFC56@benramsey.com> In-Reply-To: <41AF2CFB-BB90-40B6-AB21-2710E46CFC56@benramsey.com> Date: Wed, 4 Sep 2019 19:12:46 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Ben Ramsey Cc: Lynn , =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , Fwentish Aelondes , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Silent Types From: andreas@dqxtech.net (Andreas Hennings) On Wed, 4 Sep 2019 at 18:09, Ben Ramsey wrote: > > > Andreas Hennings wrote: > > > > In some other languages the mixed type is called "variant". > > https://en.m.wikipedia.org/wiki/Variant_type > > I mostly remember it from VisualBasic. > > Union types are probably better than specifying a variant or mixed type. = At present, parameters and properties with no type specified are mixed by d= efault. Nikita has just opened discussion on a new union types proposal in = another thread. Nothing wrong about union types, but this is a different topic. A "mixed" or "variant" type is simply giving a name to what we already have. Like the invention of the number zero. Currently afaik a variable with a type specifier is simply a variant/mixed variable with type checking added on. Which means every variable has to store the current value type. In other languages, typed variables are implemented without the dynamic type information, and only the variant/mixed/union types need this additional overhead. If we introduce this to PHP in the future at some point, this would allow for some nice optimization. > > > > Fwentish Aelondes wrote: > > > > 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 this > > 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? > > Static analyzers (like PHPStan) already honor types specified in comments= above variables. > > /* @param int */ > $i =3D 0; > > > > Micha=C5=82 Brzuchalski wrote: > > > > 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; > > I think specifying the type in front of the variable is the best option, = and we have precedence for this with typed properties in PHP 7.4. > > > Cheers, > Ben