At 17:10 14/06/2005, Sven Fuchs wrote:
> This implementation of issetor() actually works fine, except it does
> pollute the symbol tables with empty variables ($a and $b in this
> examples are created, as nulls).
What are the consequences of polluting the symbol tables this way?
Well, it will increase memory usage, but unless you're dealing with a huge
amount of variables, that should be pretty negligible. It might also not
work properly in certain cases, because PHP isn't truly capable of
differentiating between variables those empty variables and real variables
that contain nulls. For example,
function ifsetor(&$x) { }
ifsetor($foo);
print $foo;
will not generate a notice on a non existing variable, but will emit it if
the call to ifsetor() is removed.
Should this issetor() be considered a "bad practice", probably for
medium to large scale applications?
I think that a more practical implementation may be something like:
function ifsetor(&$x, $default=null)
{
if (!isset($x)) {
$x = $default;
}
return $x;
}
i.e., assign the variable with the default value if it doesn't yet
exist. I think it usually desirable (not always, naturally) and since we
want the variable to exist in this case, there's no pollution issue.
I fully agree with everyone else that wondered why we're discussing
this. People can implement this on their own, the way they want it, with
an assignment or without it, using empty() or isset(), etc.
Zeev
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php