> On Wed, Oct 10, 2012 at 5:51 AM, Clint Priest <cpri...@zerocue.com> wrote:
> > I'm not even sure that automatic backing fields are even desired, I
> > never felt the need to have them in C# and the only reason they were
> > included is because they were a part of Dennis's original proposal.
> > Eliminating them would eliminate this as an issue.
> 
> I just did a bit of research regarding this topic and I have found the 
> following reasons why automatic properties exist in C#:
> 1. Changing a field to a property breaks the binary interface, so all code 
> using the library has to be recompiled. If you are using an
> automatic property you can safely add additional behavior for it later.
> 2. Properties support data binding, whereas fields do not.
> 3. There are attributes that work for properties, but don't work for fields.
> 4. Reflection for fields and properties works differently, so changing a 
> field to a property is a BC break.
> 
> I guess that #1 is the most important one (you don't want to break the
> interface) and it obviously does not apply to PHP. Points #2 and #3 also 
> don't apply as PHP has neither data binding not attributes. #4
> also doesn't seem to apply because ReflectionPropertyAccessor defines all the 
> methods that ReflectionProperty defines, so
> changing
> field->property should be okay there too.
> 
> From that I would conclude that the automatic properties are really not 
> needed in PHP. I think they will only cause confusion as to
> when one should use `public $name;` and when one should use `public $name { 
> get; set; };`.
> 
> The only thing I'm not sure about is how read-only / write-only properties 
> rely on automatic properties with your current
> implementation. If the automatic properties aren't needed there either, then 
> I think they can be safely removed.

Nice, I would agree that we should eliminate the automatic get/set since the 
reason they exist in C# is not an issue in PHP and it has only served to 
confuse everyone.

With the read-only and write-only, they are separate from automatic 
getters/setters really.  If you define a read-only with {get;} it's the same as 
any other getter.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to