Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91744 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13761 invoked from network); 18 Mar 2016 09:09:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2016 09:09:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:33794] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/00-13075-4D5CBE65 for ; Fri, 18 Mar 2016 04:09:41 -0500 Received: by mail-lf0-f49.google.com with SMTP id e138so59048682lfe.1 for ; Fri, 18 Mar 2016 02:09:40 -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=Ott/MabxbMQjomTodqA/7Lq5zA7L1sqJZcrtntyG3Og=; b=ufhZ/gR2GAa0RiI0gaFqbDXVytfXpGuXAqYKW4YlWdo+mDGEivnkkdG+RH6HrUryzN QOV4oK/c1Lqn9vO7jeI3ouV5oVZnsfNuQ1PjXdRAy9cqTLAtMRXlnqE4qCMJKWrpPnPe HiKsysCSQwdLrNmMP/5SpmGofSTeN57VjPgOiQFF0c0AjiQ/yycFIniHZ4XOI30EcbG6 Yy/2oYipRWqHz8tlhmqpKbIn6tF3XmKJpeS6E9/WDZJf5BS5Nn+HCAqPqsq069oo4c92 b22o3QhrITJhzn1wZ1wri9ZN+mKwjkHFSmURZQc7WH+wHg87DQ2IjN5Htl9XUdxvcgCF UNKw== 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=Ott/MabxbMQjomTodqA/7Lq5zA7L1sqJZcrtntyG3Og=; b=fMfGhsY7E0H3VWDiwwSHIh+uL+qveK3+2Xvl7TuX/vZnVedyNf/Fi/oKEHtJOvFh4A 0RGBUPCwH/DNTYAcX3TvxQAlP4JVvOP5RAKvY4XEG7wQnLKPHsRPQI3Jo1CvvOeXAt7m tihYepZC7wI0ksebhy+KwqsONe41dvwFErpB1hVA/Sfg/yhTJqdKWGRMEi5n2hLlvP3S JI5UVY9Ps9ydftUchPIB8H8/TITDaQXFRxgXCxBQvhuGUDYVJgazYh9pJDanG2YA2sFJ piyZP4H1Cq245vYwQ75ZiPUpjFwi6JNGutlh3yp1k8gz8u7G8mBZodO5HCF13UnDU68N E3GQ== X-Gm-Message-State: AD7BkJKxWSPdq5NdDSG3At9WvjVxeCaX6fxcEunmq08ENAZXDtXMijr1KZm5V7Mu1xSIRwPUC4pfCnGWf5LIcg== X-Received: by 10.25.21.94 with SMTP id l91mr5433780lfi.25.1458292177672; Fri, 18 Mar 2016 02:09:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.59.167 with HTTP; Fri, 18 Mar 2016 02:09:17 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Mar 2016 10:09:17 +0100 Message-ID: To: Phil Sturgeon Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113f17d63aa32b052e4f1bb6 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: ocramius@gmail.com (Marco Pivetta) --001a113f17d63aa32b052e4f1bb6 Content-Type: text/plain; charset=UTF-8 Hi Phil, On 16 March 2016 at 17:36, Phil Sturgeon wrote: > Hello everyone, > > I have completed the draft for an RFC, to add Typed Properties. The > patch has been written by the one and only Joe Watkins. > > https://wiki.php.net/rfc/typed-properties > > I would really appreciate constructive feedback on this RFC, with a > few areas especially: > > 1. How scared are we that integers can be expanded to floats on runtime? > > 2. This whole temporary nullability situation, where unset properties > will error on attempted usage if not set. Should they instead error > after the constructor has been called if they are still not holding a > value? > > 3. Weak vs Strict. Right now this is entirely strict, with no > declare() to change mode. Reasons for this vary, from various sources, > but include "Not sure how to implement it" and "Well people should not > be using properties as part of their public API". > > Help on 3 would be appreciated. > > Also let's please avoid "PHP IS TURNING INTO JAVA" and the other > rather common rhetoric. Strict Type Hinting might have been seen as a > battleground for fans of strict and fans of weak to fight through a > keyboard, but this RFC will not be the repeat. > > We'll have a nice, orderly, constructive conversation about this RFC, > and improve the patch as you all provide feedback. > > Let me know what you think folks! > I really love the RFC, thanks for working with Joe on this. 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? 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 } } In addition to these questions, I think that the reflection API also needs a `ReflectionProperty#getType() : ReflectionType` addition in order for the RFC to be complete. Cheers, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --001a113f17d63aa32b052e4f1bb6--