>>> How does one get a reference to a property, if a property is just a
>> collection
>>> of methods with fancy behavior?  That makes properties a first class
>> entity,
>>> which is an entirely different bit of brain bending.
>>
>> Its the same concept as having a reference to a function, where you can
>> invoke the reference and it invokes the function.  I say that as a
>> programming concept, not a PHP concept, because I am a bit fuzzy in the
>> "function reference" department of PHP.
>
> I don't believe PHP has function references per se.  It has the ability
> to call functions dynamically by either:
>
> $function = 'foo';
> $function();
> // or
> call_user_func[_array]('foo');
>
> (The former is faster so preferred if you have a fixed number of
> variables.)

Right, that is what I thought.


> Functions are not first-class entities in PHP the way they are in, say,
> Javascript so you can't pass them around, nor do you have "function
> pointers" as you do in C.  (My god those are a nightmare to code...)
>
> PHP 5.3 introduced anonymous functions/closures, which seem at first
> blush to be sort of like that.  However, I believe the internal
> implementation is done using objects and you can mimic that behavior on
> an object using an interface, so really functions still don't have a
> first-class status but are emulated using objects.  (I'm sure one of the
> compiler people can correct me if that's not entirely accurate.)

Ah that is interesting then.


>> So is the solution then to make the set method return by reference?  Or
>> does that just create more problems?
>
> I'm not sure.  I'm just pointing out that "behaves like class members"
> is a substantially more complex scenario than it seems at first blush,
> and we need to think through the implications of that and just how
> closely we can emulate properties.

I completely agree.


>  > The basic Idea of a property, is making a getFoo() / setFoo($value)
> pair
>  > of methods look and act like a variable from the outside, and have an
>  > easily identifiable and simple to use syntax on the inside.  The reason
> I
>  > originally focused so much around methods, is because properties
> literally
>  > are a pair of methods in C# (thats what they are compiled into).  But
> PHP
>  > is another beast, and the challenges are different.  As long as the
>  > original purpose of properties is not loss, whatever way we figure out
> is
>  > best to implement them is fine with me.
>
> The "original purpose" being, specifically, "smarter class members",
> correct?  (The internal syntax to define them we can bikeshed later;
> determining the external syntax and semantics has to come first.)

Well when saying "original purpose" I was referring to exactly this:

"The basic Idea of a property, is making a getFoo() / setFoo($value) pair
of methods look and act like a variable from the outside, and have an
easily identifiable and simple to use syntax on the inside."

But I suppose you could just boil that down to "smarter class members" ;)

- Dennis



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

Reply via email to