Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91749 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28204 invoked from network); 18 Mar 2016 12:29:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2016 12:29:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=crocodile2u@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=crocodile2u@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: crocodile2u@gmail.com X-Host-Fingerprint: 209.85.215.54 mail-lf0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:33788] helo=mail-lf0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/42-13075-6A4FBE65 for ; Fri, 18 Mar 2016 07:29:27 -0500 Received: by mail-lf0-f54.google.com with SMTP id h198so63975016lfh.0 for ; Fri, 18 Mar 2016 05:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WHZJ/Q8yk30/M2e+TXQcbBQtb5r/4inOs7NeB8KJQC8=; b=ZmFQfP1LHMTsdIUKO5/w9Gx8mpOIqQdLwQqnbpitEwecYWjzmlnO4ujSFSXsBdibDp 4q7GfEsc+lRxtW3v4rj7JJT/kthjivLWlg9IEQiLldJnkZaAD14KsNTWl+XVnFSpbMPa wvUaWhTy6DmZEzkPJU4FHbTV3C6ll5JDFC3keZ7BjKfi2HjF29Un72kJstDVAwJWgOcM 4cSBOslvpHnAOKPRuwrTak5Pw6Y/jizm/LL2qEfp1+vQDk4KKPbmNC2ibYDG7Ssorcel d8RgC3UQabAULCyiVnnqa37CSODLjc+Z77zfQx4a+43zhx/KvIDe3IrYw2KbWepslo4t EbrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WHZJ/Q8yk30/M2e+TXQcbBQtb5r/4inOs7NeB8KJQC8=; b=hHNH0GMs6EhYGzfimM02NjXqphYQFuss5+9roQtjok8cpkk+rY8M78e6qph9SkTYTe ulThIiIoQ4VuNDPDPj13tV2Dje/Vc2/RFrNsyaGBRMUT04jGyiuDTxO7vXkFN2FPPz7G lCzAEeqsVghYJllAD9kliM8pVC1JldbL8ZF46kY65PnzsdvOzsL5SL3BJW4nkCLLkGVN eTT879fLssadZ4zar2iaFyZ18td1+kXeDuQ/Lgjp9+3DCh9Usl0qMNqPAqVGoL76Q2WZ TCBr7dAPJaBCcMCN2VKiQsl4ZiQVQGAcwdTVltrwHB1e9dPC4kOds8rWVFIXXTfj5zT8 4jzw== X-Gm-Message-State: AD7BkJLlBfuQ/tZXupJr6Pmse+erwtO4bEdFg2ou8gzPXkVLYF0pItkkwPh+dYrGiQNL6EhePuvO6IWX7v8MUQ== X-Received: by 10.25.33.140 with SMTP id h134mr5998968lfh.159.1458304163983; Fri, 18 Mar 2016 05:29:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 18 Mar 2016 12:29:14 +0000 Message-ID: To: Marco Pivetta , Phil Sturgeon Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114102c0ab3837052e51e59d Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: crocodile2u@gmail.com (Crocodile) --001a114102c0ab3837052e51e59d Content-Type: text/plain; charset=UTF-8 Just an idea of a syntax for nullable properties. What about: /** * Can be null */ public int null $foo; /** * Can NOT be null */ public float $bar; This type of syntax has a long-living predecessor - SQL (INT NULL). I think it is readable and it does not introduce ambiguity as in string|null case: one might suggest that "string|int|float|null" is also possible. In my solution, it is clear: the property either has the NULL predicate or it doesn't. Cheers! On Fri, Mar 18, 2016 at 12:49 PM Marco Pivetta wrote: > To answer my own question: the entire RFC is a no-go in its current state. > On 18 March 2016 at 10:09, Marco Pivetta wrote: > > > That said, I have a few quite common use-cases that arise and that are a > > bit problematic, both because they are hacks and because they are > actually > > used in large projects. > > > > Specifically, I'm worried about two particular use-cases: > > > > * unsetting properties > > * by-ref property assignment > > > > To clarify, un-setting properties allows us to hide properties > completely, > > loading them on a per-usage basis: > > > > class Foo { > > public int $bar; > > public function __construct() { > > unset($this->bar); // is this operation legal? For BC compliance, > > I'd expect that to be the case > > } > > public function __get(string $name) > > { > > initialize_properties_here($this); // external thing connecting > to > > db, loading files, yadda yadda > > } > > } > > > > var_dump((new Foo())->bar); // what happens here? can > > `initialize_properties_here` actually assign a non-int to `$bar`? Will > the > > type safety still work? > > > > See https://3v4l.org/bsHXH/rfc#tabs - unset() doesn't work, and that > breaks > some basic PHP semantics that are covered by phpt tests, but just for the > case of typed properties. > > > > The by-ref property assignment is a bit trickier, but can probably be > > worked around with some overhead (re-assigning). > > Here's what is going on: > > > > class Foo { > > public int $bar; > > public function __construct() { > > unset($this->bar); > > } > > public function __get(string $name) > > { > > $this->bar = 123; // default value > > $props = ['bar' => & $this->bar]; // is this operation now > > considered illegal? > > initialize_properties_here($props); // external thing connecting > > to db, loading files, yadda yadda > > } > > } > > > > > See https://3v4l.org/sKqYb/rfc#tabs - by-ref assignment is forcefully > disabled, and that breaks some more PHP semantics just for the case of > typed properties. > > To sum it up, the RFC has one major problem: it focuses on the WHEN > assignments happen, rather than just checking WHAT is assigned. > > I think the scope of the proposal needs to be reduced strictly to type > checking. > As it stands, this is too magic (and I do qu > > Cheers, > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > -- Best regards, Victor Bolshov --001a114102c0ab3837052e51e59d--