Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91748 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25235 invoked from network); 18 Mar 2016 11:48:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2016 11:48:58 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; 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: ocramius@gmail.com X-Host-Fingerprint: 209.85.215.54 mail-lf0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:36377] helo=mail-lf0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/E1-13075-82BEBE65 for ; Fri, 18 Mar 2016 06:48:57 -0500 Received: by mail-lf0-f54.google.com with SMTP id d82so16848276lfe.3 for ; Fri, 18 Mar 2016 04:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KGYyDHETOMAk13LuAzeKk5hVQ45Lwd8bSPeeY/3yBic=; b=WF1SRcuaairzPxn9ULSUEGH6J0cNhnIcAA6Go5A2wZ97LR8C+7VpSP3/lg2jeS2xV/ qgsSUvfrUrjdcp5z2cJw78ge0SNDE0td8j6Va+rPRZ7o/BIroVQi+T5vXKLmou58ns9X jOkZAlAnf97fgXEedf378nfJeXMFMsib6WUZbF3N/OE+t+top37/NY1KPXURqUpp7WlR N9hFQ6ut4/ocLdlwZy+q8daEf6U7jZ8jgyG3R+dNZV2P3IhHwltM9EEea4aVWizT6d/E XqrdqGABjhtxemR3oOR8DzWiDy25O66dmEpyK8R7H3Xq8fVV3WUN2EFhDtWvbRLnsTqd a87A== 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=KGYyDHETOMAk13LuAzeKk5hVQ45Lwd8bSPeeY/3yBic=; b=cmneNhvd1AjK/63xeDaHb5XV6ttvuZwd6OZyUQahmPN6I4I421NYSytkn4b2mWwYr3 k/CT6k5XcnTENaD1wsGw4ObOJut0AqTq5iMCoWhFqanG3go1OTQmM6ApBKkXu/8RMopZ 9Egi2yZ/Nzj5/a8dljBjM+WSs1viwRiLBCY77XNSHtBqxgXoemZOwDJIAvmPUSZSSyZw qpMb0CQV2TSjpn1/TKqujK9LmQLKV8Urs8N7R/4jnIe7uczGrDib7afAb3HVEwTSSl8P kHlQG9Ptcb9L8Bx352sOdSH7Fe9Gsp0gh6qSMEqZRNIyYxDrRpniaO9Ipuo08m3imOq5 QH6w== X-Gm-Message-State: AD7BkJJeO5rzPOX1sqyA3LPL6eRv3ZmJvjBlIEktmO9tNnMWKNNOEVoY7mOVtZ+SCqCxMtSskvFtUBTp3CwpKQ== X-Received: by 10.25.35.87 with SMTP id j84mr5697730lfj.119.1458301733812; Fri, 18 Mar 2016 04:48:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.59.167 with HTTP; Fri, 18 Mar 2016 04:48:33 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Mar 2016 12:48:33 +0100 Message-ID: To: Phil Sturgeon Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113c9ba0d1c2ce052e5154c2 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: ocramius@gmail.com (Marco Pivetta) --001a113c9ba0d1c2ce052e5154c2 Content-Type: text/plain; charset=UTF-8 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/ --001a113c9ba0d1c2ce052e5154c2--