Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96905 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75185 invoked from network); 16 Nov 2016 00:06:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2016 00:06:19 -0000 Authentication-Results: pb1.pair.com header.from=php-lists@scopey.co.nz; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php-lists@scopey.co.nz; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain scopey.co.nz from 209.85.216.173 cause and error) X-PHP-List-Original-Sender: php-lists@scopey.co.nz X-Host-Fingerprint: 209.85.216.173 mail-qt0-f173.google.com Received: from [209.85.216.173] ([209.85.216.173:35201] helo=mail-qt0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/48-05303-AF2AB285 for ; Tue, 15 Nov 2016 19:06:18 -0500 Received: by mail-qt0-f173.google.com with SMTP id c47so86999341qtc.2 for ; Tue, 15 Nov 2016 16:06:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scopey-co-nz.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=nk+/LEapfke1olK/N6x/viDrx6JINe1DLGRPa2HkNkE=; b=UO0fu9diyA96Z7fJo5sERjhtayCI5g8/UN7AG6K96QlNLfO89XN6fzAlyzqDRM3yoA psWK1VI4yHxXV6Eve1Fhy6tdSmuzEukKPP5PcdFo3NU0FjN+I/eFEHsAzjk0OXnT9VXz q+NOinR3ERtyipgSc6ECcPSnKK0LzzRYiXzKv/hA3/Juc7EHUSoW69oWbmVb2JFYZckK lx2NrCUwu5ASMA5wEfLyoJ+il3s8xg0NypGXc4IYv9pKdWfe+47AC+vzxTaEbaiAy5Ig JjP5WkrhBvE0ZBK3tGxYkAoPXm/n6B7vSOGCzQa0vg6CeFKYxSXrxE/T7ZyvfS9xLqIi r1Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=nk+/LEapfke1olK/N6x/viDrx6JINe1DLGRPa2HkNkE=; b=mWE1GBPp6sdoNzoWYoPjWTZPg/0dag3KyBQt+YeU0mx9wuOsVy1RxDZ0hM2TdHIf+3 x12h+IH61j/G1c2BReFWwj2SAoc0v1ZdrfIiexXF25U/fc3TiPqyocB+wpBE3E7TgKqJ ko8wM2IgeYsRjdZuYErKTXCNXZhnVf7+R5/ehnWAPI66cSRO4OHbEQtXCiW5wRoEf+HT kTxEUy8vnbhf2vCLUGIUo+BehO7jnrJXxQcgLsvU/6d3grQclyAG8psZ6r8+Bgv1u0RD EXra2WWag3IydrsKHMK0Wn/Gocmp3lM3CX/p9pLn232SCr+8AHiJQuUnprLlaIom7Vnz 3ylw== X-Gm-Message-State: AKaTC00Y/DDfhNXp6QJjsPNqMqxiDeI0DPDqswwSIUa0sQgJTj9p9ZjTkF5EzBWUhMiszGgOqQRBuqu26JnK1w== X-Received: by 10.237.32.205 with SMTP id 71mr54910qtb.237.1479254775932; Tue, 15 Nov 2016 16:06:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.160.101 with HTTP; Tue, 15 Nov 2016 16:06:15 -0800 (PST) X-Originating-IP: [210.48.49.168] In-Reply-To: References: Date: Wed, 16 Nov 2016 13:06:15 +1300 Message-ID: To: Michael Morris Cc: PHP internals Content-Type: multipart/alternative; boundary=94eb2c0c5e6673d4de05415fd708 Subject: Re: [PHP-DEV] Type locked variables From: php-lists@scopey.co.nz (Guy Marriott) --94eb2c0c5e6673d4de05415fd708 Content-Type: text/plain; charset=UTF-8 I think it would make more sense for typed properties to exist first, and it so happens that there was a recent RFC for this: https://wiki.php.net/rfc/typed-properties. That RFC failed by a very small margin. I would suggest you read through the discussions on the mailing list regarding that RFC for some common arguments to typing in PHP. On Wed, Nov 16, 2016 at 12:44 PM, Michael Morris wrote: > Perhaps it's time to revisit the idea of allowing variables to have their > types locked down. The keywords needed are already reserved. So... > > string $a = "hello"; > int $b = 5; > > Once declared this way the variable's type won't change unless it gets > unset. In normal mode PHP will coerce any assignment to the variable to the > desired type. If declare strict types is on then assigning the wrong type > to a variable would raise a type error. > > Note this would simplify one of the use cases of setters - insuring the > class member is of a valid type. > > The idea of function overloading reminded me of this. I'd consider being > able to do this sort of type lockdown to be prerequisite to having > overloaded functions. > > Since this approach is entirely opt in I don't think it would make the > language harder to learn. > --94eb2c0c5e6673d4de05415fd708--