Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63311 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70742 invoked from network); 10 Oct 2012 03:28:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2012 03:28:49 -0000 Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:63517] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/61-62296-07BE4705 for ; Tue, 09 Oct 2012 23:28:48 -0400 Received: by mail-pb0-f42.google.com with SMTP id ro2so205516pbb.29 for ; Tue, 09 Oct 2012 20:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=/GzAMdeuJfGyNT1n4fp075f20FWSEbuFi8X0Cz30J8U=; b=HHkh/ommToNA3585VyjHXHL6L1FvNd/X0rNWssNk7gSjrZ66sQ+4c2ZehS5eDxcvxE xMPHyVkirbRVVnkUyKJkw5Ao9BuM+k1kAoaUGX4sy1LzebLpx7ASzPbk6p7euidtV9NY KaVC9/maNJYelh5iMwwrl1//0bhrHwppQGA4/jqLy8oTVp1uj6P1r0GCm/Q8jWOUcJef 4TChbA6TIuZsg6WKNjKHsegaPhWvkZ4aO089O0O/3EjBdlf3/qCqY0GSD3Lh5BT7/82d mpd3RnKk5w6xMnmt4B3BvTOIZRJXc2tUV8wy5mf1D7SL8Bnb10rAUzAXSOCJzcINvKw9 XJKg== Received: by 10.68.135.33 with SMTP id pp1mr70086893pbb.5.1349839725824; Tue, 09 Oct 2012 20:28:45 -0700 (PDT) Received: from [192.168.1.181] (tmwpho1.lnk.telstra.net. [110.142.207.74]) by mx.google.com with ESMTPS id f9sm127437paz.1.2012.10.09.20.28.43 (version=SSLv3 cipher=OTHER); Tue, 09 Oct 2012 20:28:44 -0700 (PDT) Message-ID: <5074EB6F.4030809@gmail.com> Date: Wed, 10 Oct 2012 14:28:47 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 MIME-Version: 1.0 To: Jazzer Dane CC: Christian Kaps , internals@lists.php.net References: <9570D903A3BECE4092E924C2985CE485612B3B48@MBX202.domain.local> <5073328D.5000002@gmail.com> <50735165.8010703@aaronholmes.net> <9570D903A3BECE4092E924C2985CE485612B4353@MBX202.domain.local> <760ab4f994a78a846cf86aafda71e0e2@mohiva.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 From: davidkmuir@gmail.com (David Muir) On 09/10/12 19:20, Jazzer Dane wrote: > - "If we ever get return type hinting/checks then we needn't consider how > the syntax has to look" From what I know, this isn't planned for PHP 5.5 > and any proposals for it have been largely ignored. Return type hinting > won't help when setting either, although it would help with getting. All > that being said, type hinting aside, the syntax I proposed is, in my > opinion, the most consistent out of any other proposal thus far (arguably > aside from yours, I'll go over that momentarily). Excellent point. Return type-hints only affect the getter, and even then it could be a moot point if the property itself could be bound to a particular type. It would actually be a much cleaner solution, and wouldn't require any superfluous parens in the declaration: class MyClass{ public SomeClass $property { get {...} set {...} } } $foo = new MyClass; $bar = new SomeClass; $foo->property = $bar; //ok $foo->property = new StdClass; //type mismatch Heck, half the time setters and getters are implemented specifically for this purpose. If the property itself could be typed, then 90% of the time we wouldn't even need to specify get/set. Just give the property a type and be done with it. That said, it wouldn't help for scalar values, and that leads to a problem with the current syntax (AFAICS). You can't specify the initial value for a property: eg: class MyClass{ public $property = 5 //?can we do this? { set($value){ if(!is_int($value)){ throw new InvalidArgumentException('value of wrong type'); } $this->__property = $value; } } } Or would that have to happen in the constructor? class MyClass{ public $property { set($value){ if(!is_int($value)){ throw new InvalidArgumentException('value of wrong type'); } $this->__property = $value; } } public function __construct(){ $this->property = 5; } } Cheers, David