On Tue, Aug 19, 2003 at 05:32:41PM -0500, Shaun Thomas wrote:
> > > 2.) variable_exists can not be written in PHP.
> >
> > And it is not necessary, because get_defined_vars() exists.
>
> Which is just plain gross, but let's continue on...
How many local variables do you have? That array shouldn't be too big.
> > Noone ever said said that.
>
> Actually Zeev did.
No, he did not. He said ``Don't use null as a value'', which is correct.
It is not - it's nothing.
> > Still no need to test for their existance, imo.
>
> I agree. Apparently you missed this part:
If it's not needed... why implement it?
> > Since your presumptions are flawed, the conclusion is also.
> > And, given good design, where would you need it?
>
> Why do things always come down to the wonderfully nebulous "good
> design"? What is "good design"? And now that you've demonstrated that
> the isset+is_null check doesn't work, the issue becomes even more
> prevalent - since there is now no way to escape.
Wrong. array_key_exists('var', get_defined_vars()).
And about good design... you asked for it:
Good design, in my opinion:
Encapsulate. If noone messes around with your variables from outside,
you won't get variables that you did not define, and so - no need to
check for them.
> Personally, I would never use variable_exists. But if you want to say
> get_defined_vars works, why do we have function_exists? I could just as
> easily say, "Use get_defined_functions and check for the function you
> want. function_exists is a waste of time and bad design." It's a
> completely arbitrary and subjective position. The inconsistency itself
> should say something about this issue.
>
> So I ask this:
>
> get_declared_classes, class_exists
> get_defined_functions, function_exist
> get_defined_constants, defined
> get_defined_vars, ???
classes, functions, constants are available everywhere, not just in the
current function. Including a foreign library adds classes, functions
and constants, but it won't mess with your variables if you encapsulate
properly. Additionally, for variables: isset() suffices. If a variable is
null, you can treat it as nonexistant.
> Or does PHP win the language inconsistency award?
It already does that (naming(strpos, str_replace), argument order), but
that has nothing to do with variable_exists. (indeed, this name would
add inconsistency, because it's called var everywhere else ;))
This is my last mail to internals about this topic, it's been discussed
enough imo.
--
Regards,
Stefan Walk
<[EMAIL PROTECTED]>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php