Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106842 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40740 invoked from network); 4 Sep 2019 09:48:30 -0000 Received: from unknown (HELO mail-io1-f68.google.com) (209.85.166.68) by pb1.pair.com with SMTP; 4 Sep 2019 09:48:30 -0000 Received: by mail-io1-f68.google.com with SMTP id x4so41890472iog.13 for ; Wed, 04 Sep 2019 00:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mtxUgDzcV9cabaH+WKoUvrdUeyJlW0tpIR2TukKkc6U=; b=JmZtOnkw3RZ6uo/xMrj+C39lzQhhxx+wg8pzlDpOUnWrxp95TS+GbF7AqnAHMrxwIg GQ9FEjuccAhPuZugEe8jCYpbGp3hXnWp3chkOMXzfxhnaVe888Izc3SOC4mxcPFS/mhF yLlBG3UkSSZXbPhOgdPdZfDeE0/ddCmeHALyncrEcVE5BcHBrsdJgg5B1b+sGEDIDQGJ GU3pEr8Raz6o/+jpViFd00Fiyud1vdZYiFx6eeMiw7NCH+PuVGakIAUbTAPy6vmsvjGK 7sdvWFDqj5VsKfsbv5yeOGRX1UJtCyIERFjOU06hlzs6GlScqYnxm7rP091xxBXMFDC3 5LlQ== 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=mtxUgDzcV9cabaH+WKoUvrdUeyJlW0tpIR2TukKkc6U=; b=d46jnCu24E0m2BsJ99WoNEdoUTBMggBHcDi9w5eswANNwO9MugW3AccUAbWb5bDL7q 1aoens/fbcok3LDapRuRghpz/TbnhXYnnCh0BfL7+K5hKwKqsU0Q4sA+AhAnRuNnx2iG S7ve9Jnuv8ftG7CAXIvVHScdkxrDthgBme/xyak7a9nkYVujkZBegJIAOaXT3mQ8IM8o Mlx6JDYmSMZdiVWDX54xukGB0rnnqu1UH8OPImxPJXmzhK5r3SEv9LcV7eQ8xzoCOClT wrRRMeEyh+gDpkJcdztruBu8R2b4oOq7m4jtxBeKgvPl0Zb7vsYvRn2CWDi2he96Rg7g k+MQ== X-Gm-Message-State: APjAAAU3YbdK+PFoq6e09kwM1T/CFNadYOu6WDkMztqUSs232YsEVN+A 7MJ/FfBG4bfZYaMnS/1FHF17e/jXxaho+5ChfGc= X-Google-Smtp-Source: APXvYqy+R+h4S5qzcXZ+mrMQUTblZnTUWqyFKcDUt5Kea5AsXiW+AZ5H6uu7TCY1Z2qqCeEYfFFGtWj1ggOY31JWeb8= X-Received: by 2002:a5e:d707:: with SMTP id v7mr6442034iom.114.1567581740870; Wed, 04 Sep 2019 00:22:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Sep 2019 09:21:54 +0200 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: Fwentish Aelondes , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d22f5c0591b51096" Subject: Re: [PHP-DEV] Silent Types From: kjarli@gmail.com (Lynn) --000000000000d22f5c0591b51096 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 that 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 not 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, based 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 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? > > > > 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 > --000000000000d22f5c0591b51096--