Hi Davey,

> Object properties (or members, classic ->var, not this proposed syntax)
> CURRENTLY, work this way:
>
> php -r 'class foo { public $bar; } $foo = new foo();
> var_dump(isset($foo->bar));'
> bool(false)
>
> This is because you are confusing PHP's isset() with a property_exists().
> Is set. Is the variable (or member/property)
> set to a value?

I did not know of property_exists(), very interesting!


> In this case, both isset() and unset() work with the property get/set you
> are proposing. Imagine:
>
> $results = $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM some_table WHERE
> foo = 'bar');
>
> if (isset($results->count)) {
>       foreach ($results->getResult() as $result) {
>               // Do something
>       }
> }
>
> where isset() would hit:
>
> protected property count {
>       isset {
>               $result = $this->execute('SELECT FOUND_ROWS()');
>               $this->count = $result->getColumn();
>               if ($this->count == 0) {
>                       return false;
>               }
>               return false;
>       }
> }
>
> Not an ideal example, but it gives you an IDEA off the top of my head of a
> way to take advantage of it

Well, I understand the concept and how it would work, but I just don't
think its logical.  In my mind, being able to make a property appear to
disappear makes as much sense as making a class method appear to
disappear.  This is absolutely no good for inheritance for one thing.

The __isset method makes perfect sense, because all variables handled with
__get and __set don't truly exist.  They are not actually defined in the
class, they are just "fake" class members, whose data comes from somewhere
else - maybe an array.  So __isset is there to say which "fake" member
names do and don't exist.

But when defined, a property, like a method, shouldn't be able to just
"disappear".  It is a specific definition and should never appear to be
missing.  If you need a class member that can be unset, you should be
using __isset __get and __set, because that is exactly what those are
meant for.


My feelings are that a property "foo" should behave exactly like a
getFoo() and setFoo($value) pair of methods.  You can always call these
methods, and never worry that you will get a "method not set" error.  When
you call getFoo() you are always guaranteed to get something, even if it
is simply NULL.

Maybe I am missing your point?  But it does not make logical sense to me,
the way you suggest.

Also, would adding isset not make properties much slower?  Calling
$object->foo would first have to call and process the "isset" method to
determine if it is set, then after getting "true" from isset, it would be
able to call "get".  And what happens if there is no "isset"?  Is it just
always guaranteed to be set then?

- Dennis


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

Reply via email to