Welcome Guest, Not a member yet? Register   Sign In
Checking a variable for existance without isset(), empty(), or any other function
#9

[eluser]BrianDHall[/eluser]
[quote author="John_Betong" date="1259062666"] 

Your question certtainly is food for thought

From my limited experience I endeavour to write code without any errors because
the application seems to be much more nippier if there are no errors.

Using isset(...) I think is a KLUDGE because one is relying on PHP to trot off and
search to see if the variable has been set is in the boolean, numeric, string, array, etc
list of variables. After eliminating all possible options isset(...) will return your query.
This must take processing time.

I would be tempted to ensure your $potential_element has a default value and
therefore eliminate the search. Is it possible set a default value and run tests
with and without the default variable?
 
 
 
edit: spelling.[/quote]

The performance test does seem to strongly support that less errors automatically equals a faster program, so it isn't a question of imagination.

Now, I had thought isset() would require considerably less work than it seems to, but you point out perhaps precisely why - it might very well run multiple type checks before returning. I'm just surprised empty() doesn't require even more work, but go figure.

Well, the problem with default value is in this particular instance it is loading arrays not only with files from the file system, but then parsing out bits of the filename into an array, which is then formed into an associative array. Its meant to be a very easy to use, slightly magical, banner ad system. Its complicated by the fact that the program needs to know about the contents of the file before ever opening it due to its interaction with another far larger array (200-1000+ multi-dimensional arrays itself) - but ultimately I have no idea what could be in any of the elements before the application is run.

That's rather why I'd never really considered this before - never really had a need to blindly walk through a significant sized array, but this extreme example helped to expose some underlying assumptions.


Messages In This Thread
Checking a variable for existance without isset(), empty(), or any other function - by El Forum - 11-24-2009, 02:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB