Just to be complete ;)
D:
int hidden_name;
public int the_var_name() { return hidden_name; }
private void the_var_name(int s_value) { hidden_name = s_value; }
ref: http://www.digitalmars.com/d/archives/56.html
Regards
Alan
Jeff Moore wrote:
On May 16, 2006, at 7:28 PM, D. Dante Lorenso wrote:
I'm not familiar with this OOP concept from any other language.
Perhaps it exists, but if it doesn't, is there a reason why?
Hello,
Its hard to find a major OO language that does not have
property/accessor method support.
C#:
private int x;
public int X { get { return x; } set { x = value; } }
Ruby:
def name, def name=(x) syntax plus attr_reader, attr_writer shortcuts
http://www.rubycentral.com/book/tut_classes.html
Delphi:
Property Name : Type read Getter write Setter;
Python:
I'm not very familiar with python, but it appears to have accessor
method support:
http://www.python.org/download/releases/2.2.3/descrintro/#property
Visual Basic:
Public Property Name() As String
Get
Return NameValue
End Get
Set(ByVal Value As String)
NameValue = Value
End Set
End Property
Objective C:
Key Value Coding
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueCoding/KeyValueCoding.html
Smalltalk:
name
^name
name: aValue
name := aValue
Java:
Java doesn't have a specific language syntax, but it does have a
standard for declaring accessor methods.
http://java.sun.com/products/javabeans/docs/spec.html
C++:
I'm not very familiar with C++ and I don't know what is standard,
but tool builders such as Microsoft and Borland have had to add their
own property syntax to C++.
PHP:
PHP doesn't really have accessor method support. __get and __set are
property missing handlers, not accessor methods. This leads to
several problems:
1. __get/__set are too cumbersome for simple use cases. (Hence this
thread)
2. __get/__set is slow. (In the best case: about 10x slower than
simple property, 3x slower than an accessor method call)
3. properties defined with __get/__set can only be public
4. Reflection does not work with __get/__set
5. Source code analysis does not work with __get/__set (no phpdoc,
annotations, auto completion, etc.)
6. No support for static properties via __get/__set
7. __get/__set is error prone. Mistakenly creating a simple property
of the same name disables the magic methods.
8. Some obscure design problems with inheritance not worth going into
here.
The Pandora's box of complexity was opened when PHP got __get and
__set. readonly or readable is just a bandaid that fixes one use
case of one problem, but does it in a way that doesn't help fix any
of the other problems in the future.
There is nothing wrong with simple properties in PHP just the way
they are now. There is also nothing wrong with __get or __set. They
work well when you truly need virtual properties, such as for an
active record or a proxy class.
What PHP is missing is a way to associate individual accessor methods
with individual properties, just as you can in Java, C#, Ruby,
Delphi, Python, Visual Basic, Objective C, Smalltalk, and sometimes
C++. (To the best of my knowledge.) Read only is a special case of
this capability.
Best Regards,
Jeff
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php