Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63474 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4767 invoked from network); 16 Oct 2012 17:17:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Oct 2012 17:17:58 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:48056] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/A1-29764-5C69D705 for ; Tue, 16 Oct 2012 13:17:58 -0400 Received: by mail-lb0-f170.google.com with SMTP id gm13so4533821lbb.29 for ; Tue, 16 Oct 2012 10:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=i1OIiVvixPaaHQ1/Mg1aYftw6yR9AWPLJdRdfOnL7V0=; b=gAeAvDW890TOyB4WcbMX2rHQVi9Go201hjke3lbhUHtNhswmLSKDHKbBoiz5nfyHVL 1tcra5ED93r6XxN+kVvNGotM2j3rADDde8DG3JByPPmyhgatWXfSYoeGW3BaTu5cDt9V jfcrtOYMKWO41V3AToYU3PCIH9s2iBkuBktXbNRoGWIfXd15M1zbJ2wzFKMDA4kb1T8E vUg6w9iagLzmae0F8k7VXVPrpXrzDORlvJgc9oeWqA70Rf5T3i0yfwOjEXm+6yRqpr1C bBzXMnw6rznYM8myoCXnItmISd6f/BvX7y0ZdVyuYNDMIw78EJ3Oj69KBtylTn/TolQj fqvg== MIME-Version: 1.0 Received: by 10.112.29.199 with SMTP id m7mr5522181lbh.2.1350407872534; Tue, 16 Oct 2012 10:17:52 -0700 (PDT) Received: by 10.112.36.39 with HTTP; Tue, 16 Oct 2012 10:17:52 -0700 (PDT) In-Reply-To: References: <9570D903A3BECE4092E924C2985CE485612B6434@MBX202.domain.local> <507D133A.4040701@sugarcrm.com> <507D801E.7070508@lerdorf.com> Date: Tue, 16 Oct 2012 11:17:52 -0600 Message-ID: To: Amaury Bouchard Cc: Rasmus Lerdorf , Stas Malyshev , Clint Priest , "internals@lists.php.net" , "Nikita Popov (nikita.ppv@gmail.com)" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2 : Typehints / Accessor Syntax From: morrison.levi@gmail.com (Levi Morrison) On Tue, Oct 16, 2012 at 10:31 AM, Amaury Bouchard wrote: > 2012/10/16 Rasmus Lerdorf >> >> The rule in PHP for any sort of type hinting is that it is only done for >> non-coercable types. In cases where there is simply no way to recover >> from passing the wrong type, it is good to catch it as early as >> possible. Extending this to also cover scalar coercable types would be >> disastrous for the entire ecosystem and would completely change PHP. > > > My point was not about scalar types. It was about porting the logic of > parameters type hinting to object properties. Nothing more, nothing less. > > >> And the fact that it is "optional" means absolutely nothing because once >> some piece of your system has "optionally" decided to use it you don't >> have the option not to abide by it, and it certainly isn't a hint, it is >> a strong type. You will end up casting every call to everything all the >> time just to be safe. > > > I use parameters type hinting everyday. I can say it's very useful. And I > never needed to cast anything. > If the object model is used wisely, and if type hinting is used as an option > (i.e. don't use it when you know you'll need "mixed" data), it's a very good > thing. > > I don't see why it couldn't be as good for properties as it is for > parameters. But Stas said it was already discussed a lot here, so I give up. > :-) It is foolish to think that these two bits of code are behaviorally different: class Entity { DateTime $last_modified; } //vs class Entity { public $last_modified { get(); set(DateTime $last_modified); } } The latter is a more verbose way of saying the former (assuming the get returns the same type as the set accepts). The latter is definitely capable of doing more than the former, such as private set and public get. The former piece of code is simply a public get and public set such that the type is always DateTime. It would be nice to have the former syntax because of how succinct it is, but I am not an experienced core programmer. I am unsure how feasible it is to implement.