Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65121 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22608 invoked from network); 23 Jan 2013 20:00:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2013 20:00:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.219.42 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.219.42 mail-oa0-f42.google.com Received: from [209.85.219.42] ([209.85.219.42:44031] helo=mail-oa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/A2-30997-46140015 for ; Wed, 23 Jan 2013 15:00:36 -0500 Received: by mail-oa0-f42.google.com with SMTP id j1so8973350oag.15 for ; Wed, 23 Jan 2013 12:00:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=JwlqGug8aXwwP65c74s0OC1f2f+yUGSlnKdYFU3KyHQ=; b=h7jC9kjd9ka5c7pcms9R/eqt6uNUqgxkKe0RDa/lJBOj+ZNbB+CXqCWFzxyMUhmMi/ Wwq6C20DUHgl4giVJ41PP/bo0Y7LXYXOtpaSLVNS7C/GVdNQDKZFgF7gf8knZCjNQ2UE Q4zzv7GDh0wkprIdzuI+15NtMclkiB20ca/1h1zGbVkXYkixmMlXYmnnr7/q4uwHydAt AbC0iP6m8opLNimHBxGLim8UO5ExdUYWuD7560hvp9ulX8aLuca9GMQLcC9hSLctcaj4 Z1gReUXMJh3A/yj5tnWA2tvtfefnw/QJ+p1IB7+SLNgKApQ29Vy2wOw+1UMrjdvkQbwJ 9H5Q== X-Received: by 10.60.31.8 with SMTP id w8mr2079332oeh.55.1358971234123; Wed, 23 Jan 2013 12:00:34 -0800 (PST) Received: from Ralphs-Mac-Pro.local (ip174-73-14-247.no.no.cox.net. [174.73.14.247]) by mx.google.com with ESMTPS id d17sm16209023obu.0.2013.01.23.12.00.23 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Jan 2013 12:00:24 -0800 (PST) Message-ID: <51004156.1060806@ralphschindler.com> Date: Wed, 23 Jan 2013 14:00:22 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: internals@lists.php.net References: <510038C9.5000900@mrclay.org> In-Reply-To: <510038C9.5000900@mrclay.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlEfHKTx3ti8Blyb9JtECO93quyJ0jvJdbTFpChQQOSPbaPCSmtsinAeBZZQ2i4tXmoNr1C Subject: Re: [PHP-DEV] C# properties vs. accessors RFC From: ralph@ralphschindler.com (Ralph Schindler) Hi Steve, > 2. C# has no issetter/unsetter. > > IMO customizing these functions is completely unneeded for the vast > majority of use cases and could be replaced by simpler logic: > isset($this->prop) calls the getter and compares to NULL; > unset($this->prop) passes NULL to the setter. I tend to agree here- I don't see a ton of value in isset/unset accessor functions. > 3. C# has no auto-implementations. > > IMO auto implementations have some value removing boilerplate, but we > should not make them violate #1. We could have the property syntax > specify what field to use for underlying storage, or simply conclude > that the boilerplate is worth the clarity. Not completely true: http://msdn.microsoft.com/en-us/library/bb384054.aspx > I think the path forward is to determine how we can serve the same goals > as this RFC, but retain the conceptual simplicity of the C# > implementation and maybe syntax that strays less from current PHP. > > I have some ideas that I could start forging into an RFC. Consider this: > > class Foo { > private $_bar; > public function get bar { return $this->_bar; } > public function set bar { $this->_bar = $value; } > } This is too similar to what we have today: class Foo { private $_bar; public function getBar() { return $this->_bar; } public function setBar($value) { $this->_bar = $value; } } > Advantages I see over the RFC: > * It's clearer that the accessors map to regular methods, and you know > how to control visibility of methods and how they're inherited. > * It's clearer $bar doesn't exist as a property, and it will never show > up in state inspection. > * You know $_bar is a plain PHP property, and you can initialize it > directly in the constructor; we don't need an "initter". > * There are no guards/proxies/shadow property to think about Personally, I don't see why 'default' can't be used: class Foo { public $bar { get; set; default 5; } } This solves the var_dump() problem, and if people want dynamic get returning something other than the property/field value, so be it. C# does indeed have an internal field per property though, even if it is an anonymous backing field. -ralph