note 87098 added to function.isset
| From: | DanielSmedegaardBuus at osu1 dot php dot net | Date: | Wed, 19 Nov 2008 10:37:10 +0000 |
| Subject: | note 87098 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146696@lists.php.net to get a copy of this message | ||
This is terrible. We have no real isset() function in the sense that it should check if something is
SET. It is misnamed, it should be "is_set_and_not_null()", just like empty() should be
"empty_or_zero_or_false()" and nl2br() should be "prepend_nls_with_br()". The
only difference between isset() and !is_null() is that is_null() triggers an error if you try to
access undeclared members, while isset() does not.
There is no practically feasible way to check if a member of a class exists if it is set to the
value null (this is NOT the same as not being set! null is a value, not a state). Consider this:
class ClassName {
public static $state = null;
public function &__get($name) {
if (isset(self::$$name))
return self::$$name;
trigger_error('No such member', E_USER_WARNING);
return null;
}
}
$class = new ClassName();
if is_null($class->state) // Will trigger an error 'No such member'.
{
start_something(time());
$class->state = 'running';
}
This is just an example to show you what I'm talking about. Please don't start with the
"Why would you do that?" or "You should do this!", because that's not the
point.
The point is that we have no way to know if a member is really declared without doing something like
(self::$$name === null) in the magic function while temporarily running with a custom error handler
to "catch" the error that will be triggered by is_null() if it isn't declared. This
isn't exactly feasible when considering the performance issues.
Now why don't we have access to whatever construct php uses internally that is used to
determine that it's time to throw a "Fatal error: Access to undeclared static property:
ClassName::$i_do_not_exist"? This is what we need, not this is_set_and_not_null() function.
----
Server IP: 87.54.44.10
Probable Submitter: 62.243.22.18
----
Manual Page -- http://www.php.net/manual/en/function.isset.php
Edit -- https://master.php.net/note/edit/87098
Del: integrated -- https://master.php.net/note/delete/87098/integrated
Del: useless -- https://master.php.net/note/delete/87098/useless
Del: bad code -- https://master.php.net/note/delete/87098/bad+code
Del: spam -- https://master.php.net/note/delete/87098/spam
Del: non-english -- https://master.php.net/note/delete/87098/non-english
Del: in docs -- https://master.php.net/note/delete/87098/in+docs
Del: other reasons-- https://master.php.net/note/delete/87098
Reject -- https://master.php.net/note/reject/87098
Search -- https://master.php.net/manage/user-notes.php