Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101514 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51984 invoked from network); 3 Jan 2018 17:21:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2018 17:21:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.47 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.47 mail-lf0-f47.google.com Received: from [209.85.215.47] ([209.85.215.47:37716] helo=mail-lf0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/71-23177-D211D4A5 for ; Wed, 03 Jan 2018 12:21:50 -0500 Received: by mail-lf0-f47.google.com with SMTP id f3so2401107lfe.4 for ; Wed, 03 Jan 2018 09:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=q1a6hCKDFEvXJohX/F9HyIJBsf+3DjnR3scfSnCxm3Q=; b=Gak0vW/6gVlUDoY8CGNxCUtDSbxrxyFMilHG0D90z4UORc7Xyo1Gbsdaelpx804fIl veApg+5fdwQYmrUTyMkb35pgfszeYmhSuiVN4IvIXpIs+ICot2wXG+v8TVLlALtjiMfn KuFjPBJeoh8cs8A3AubeBnvDkXg+2q/5ajPnFfbhcx2oqYVr5KbvSY6Z95haAQTmObLa cAH0atJQF3Twsx96t4IvD13RiId1Bqb4qzSrC3ngDnadVT9FMQpx8BZVFWesViOy6ryF AoaIEpMZXK5zjg3VDUop2F3mWBzdCq1KwxNGZ+k5kTqO0CPPIc8kOtOKcepF81CebdB6 d1ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=q1a6hCKDFEvXJohX/F9HyIJBsf+3DjnR3scfSnCxm3Q=; b=AXEx/ZeShLqTXkvcg6sTwQIhZOFvCV80FS2qYxxPC/DW3nrUpkxe/lg9Qk/BLKNX/G juUaO8SHoWFFtwgSYM69dxUx7YPo5z388onU8uQYN31MRNiKdoR1DQUZBEHB44s6HnhC olK7rSvLhzeypiBwoEL8wkzxkL7Beh/1PhRMkG7eCFaTZAPoyV9BIB6KQv+QvhY1xyRX pg8Ylwpe5FvbdtQdNYDNmuwMWiQc39GbEirO5GEW525ffGzkCwKygDg/lCgvm1vrZz7n J1g9n0rWmt2/VYNU0auXk9uc/aooJOX2SKy945qF0mWJ3wvwDeWLVuZHEwU1HvcaEpzz kcTQ== X-Gm-Message-State: AKGB3mLdORZWBGIyP40k0Qu0mCNjhOBV8ENwVFgP1irFoU84C4aFCh1b 5bbK12swUqBgiLWyCE2g/zvtXvYl X-Google-Smtp-Source: ACJfBotpoHalpKEXAftCBAsNq3WBeTLwto1SFYNAPOfu4xbGv31+Xv54Jps7KM2ZThJICxwCwjPLlA== X-Received: by 10.25.209.71 with SMTP id i68mr1247144lfg.39.1515000105794; Wed, 03 Jan 2018 09:21:45 -0800 (PST) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com. [209.85.215.45]) by smtp.googlemail.com with ESMTPSA id p62sm264908lje.67.2018.01.03.09.21.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jan 2018 09:21:45 -0800 (PST) Received: by mail-lf0-f45.google.com with SMTP id c19so2402705lfg.3 for ; Wed, 03 Jan 2018 09:21:44 -0800 (PST) X-Received: by 10.46.21.87 with SMTP id 23mr1259904ljv.107.1515000104579; Wed, 03 Jan 2018 09:21:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.201.210 with HTTP; Wed, 3 Jan 2018 09:21:23 -0800 (PST) In-Reply-To: References: Date: Wed, 3 Jan 2018 18:21:23 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Michael Morris Cc: Niklas Keller , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Strong Typing Syntax From: andreas@dqxtech.net (Andreas Hennings) Another idea I have when reading this proposal is "implicit" typing based on the initialization. E.g. $x = 5; $x = 'hello'; // -> Error: $x was initialized as integer, and cannot hold a string. or $x = $a + $b; $x = 'hello'; // -> Error: $x was initialized as number (int|float), and cannot hold a string. To me this is only acceptable if the implicit type can be determined at compile time. So: if ($weather_is_nice) { $x = 5; } else { $x = 'hello'; // -> Error: $x would be initialized as int elsewhere, so cannot be initialized as string. } This change would be controversial and leave a lot of questions. It would be a BC break, unless we introduce yet another declare() setting, e.g. declare(implicit_types=1). It could be tricky for global variables, or in combination with include/require, where the variable can be seen from outside a function body, and outside the range of the declare() statement. I only mention it here because it relates to the proposal. I do not have a strong opinion on it atm. On 3 January 2018 at 18:10, Andreas Hennings wrote: > This proposal contains some interesting ideas, which I see as separate: > 1. A syntax to declare the type of local variables. > 2. A syntax to declare the type of object properties. > 3. Preventing local variables, object properties and parameters to > change their type after initialization/declaration. > > For me the point 3 is the most interesting one. > I think the other points are already discussed elsewhere in some way, > although they are clearly related to 3. > > Point 3 would be a BC break, if we would introduce it for parameters. > Current behavior: https://3v4l.org/bjaLQ > > Local variables and object properties currently cannot be types, so > point 3 would not be a BC break for them, if we introduce it together > with 1 and 2. > But then we would have an inconsistency between parameters and local > vars / object properties. > > What we could do to avoid BC break is to introduce > declare(fixed_parameter_types=1) in addition to > declare(strict_types=1). > For local variables and object properties, the type would always be fixed. > But for parameters, it would only be fixed if the > declare(fixed_parameter_types=1) is active. > > Maybe to make it less verbose, we could say declare(strict_types=2), > which would mean the combination of both those things? > Or some other type of shortcut. > I think we will have to think about shortcuts like this if we > introduce more "modes" in the future. > > >> Currently the var keyword is used to formally declare a variable. > > Are you talking about local variables? > In which PHP version? https://3v4l.org/o0PFg > > Afaik, currently var is only used for class/object properties from the > time when people did not declare the visibility as > public/protected/private. > > >> If the type is omitted, scalar is assumed. If Fleshgrinder's scalar RFC is >> accepted then it would make sense to allow programmers to explicitly >> declare the variable as a scalar, but in any event when the type is omitted >> scalar must be assumed for backwards compatibility. > > If no type is specified, then "mixed" should be assumed, not "scalar". > Assuming "scalar" would be a BC break, and it would be confusing. > > > On 3 January 2018 at 10:03, Michael Morris wrote: >> On Wed, Jan 3, 2018 at 3:50 AM, Niklas Keller wrote: >> >>> Hey Michael, >>> >>> I don't think the BC break is acceptable. You argue that scalar type >>> declarations are relatively new, but in fact they're already years old now. >>> They're used in most PHP 7+ packages. Even if changing types might be >>> discouraged, it still happens a lot. >>> >> >> Hmm. Well, that aspect of this can be dropped. What about the rest of it?