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?
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
- Davey
On Nov 30, 2010, at 7:31 PM, [email protected] wrote:
>>> That is true for PHP variables. isset is basically saying "does this
>>> variable exist", and unset is saying to get rid of it.
>>
>> This is also true for object properties - see magic methods. I don't see
>> why you shouldn't be able to unset them - you can do that with regular
>> properties... So what you imagine would happen if you call
>> unset($foo->property) or isset($foo->property)?
>
> As I replied elsewhere:
>
> Its not a matter of consistency - Properties, as a cross-language concept
> are not meant to work that way. You need to think of a property as a set
> of two methods that just have a pretty syntax. Methods cannot be unset,
> and nor should properties be allowed to. isset() should simply tell us
> whether a property with the specified name is part of the class or not.
>
> isset() in the way you suggest would just be confusing. It would allow is
> to say that a property does not exist, when in fact it does exist. This
> is not logical.
>
> __isset is a whole different matter, without it we would have to assume
> that every possible member name in a class either exists or does not
> exist. This is because __isset, __get, __set and __unset can handle ANY
> member name.
>
> Properties are bound to a single member name, therefore, they always
> exist, unless you were to physically remove that property from the class,
> which, like methods, that is not possible.
>
> - Dennis
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php