1

As the notice is off in my php config it does not show notices in website. But i can see a lot of Undefined index /undefined variable in the server log/php log

Will this affect system performance by any chance.

If i decalre these variable and assign null to these , error will go. As it is defined.

Another doubt is , in some cases those variables will not be using.

So i declare and assign somany variable and if i am not using those variables . Will this affect the performance.

Charles
  • 50,943
  • 13
  • 104
  • 142
zod
  • 12,092
  • 24
  • 70
  • 106

3 Answers3

4

Nope.

None of your concerns are performance related.

Performance is not the only darn thing to care of.

I noticed some other questions of this kind recently (1),(2) and it's scaring me.
Because these questions lacks very basic thing: a sense.

Every thing in this world has not only it's cost but also it's sense.
And I'd say that sense is main reason to prefer one thing over another.

Say, there are 2 kinds of dishes, a heap, filthy and dirty one vs. clean, healthy and taste but more expensive one. Would you always prefer only cheap one, just because of it's cost? I doubt so.
Walking is great way to save a carfare. Do you always walk, no matter of the distance, obstacles and destination? Is cost being the only reason you're taking into account? I doubt so.
You're traveling by some vehicle sometimes, just because it's more reliable way in certain circumstances. So, you choose things my sense, not by cost.

Same here.
If you have some errors in your code, these errors should be your concern, not related performance. If you have your logs flooded with waste errors, obscuring real important ones, you have to turn these minor ones off. Not because of system's performance but because of programmer's performance, letting him get in touch with site heartbeat.

The sense, the meaning of the matter should be your concern. Not abstract "performance". There are languages apparently faster than PHP, say, assembly language for example. So, being concerned only in performance, you have to use assembly language only. But you choose PHP for it's reliability. So, be consistent, choose things by their sense, not imaginary(!) performance.

When you're asking about code structure, it's reliable code structure should be your concern, not imaginary performance issues. Isn't it obvious?

Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 7
    Notices do have an impact on performances, actually -- see http://stackoverflow.com/questions/1868874/does-php-run-faster-without-warnings for some numbers ;-) – Pascal MARTIN Mar 17 '11 at 19:02
  • @Pascal you know I call these useless "tests" as "zillion iterations of nothing". When you face an error, it's not performance that should be your concern, but error itself. – Your Common Sense Mar 17 '11 at 19:07
  • 1
    Of course, with an error, it's the error that matters ; but, considering the question, which was *"does it affect performances"*... – Pascal MARTIN Mar 17 '11 at 19:12
  • @Pascal SURE IT DOES. Given such legacy code one can have no doubts that code itself is way unoptimized as well as database stuff and algorithms. So, entire code should be refactored. While *performance* question should be asked out of real life experience, not out of useless curiosity. – Your Common Sense Mar 17 '11 at 19:15
  • 1
    Curiosity is how we learn ;-) *(I don't disagree with the "code not optimized" part of your comment, of course)* – Pascal MARTIN Mar 17 '11 at 19:18
  • 1
    @Col What else we have to care of other than performance. For an end user he will expect a better performance. If i remove notice and if its good for performance .what is wrong in that !!!!!!!! – zod Mar 17 '11 at 19:22
  • @Pascal curiosity brewed on ignorance will lead to misunderstanding and delusions. And PHP is already king of delusions. Notice second sub-question: `what if I define a variable but don't use it - would make terrible impact on performance?`. – Your Common Sense Mar 17 '11 at 19:23
  • @zod thank you for your comment. I thought to extend my answer with explanations but now I see it will be in vain. Good luck – Your Common Sense Mar 17 '11 at 19:24
  • 1
    @Col Your answer itself a big delusion. You can say that that is wrong or that is correct. But you are saying Kings Speech – zod Mar 17 '11 at 19:25
  • 1
    @Col you make me cry .please extend your answer with explanation :-) – zod Mar 17 '11 at 19:27
  • i agree with @Pascal and @zod, +1 guys. – RobertPitt Mar 17 '11 at 20:13
  • Yes, performance is important. I don't mind this question. But in this particular case, you should *always* define variables regardless of the performance outcome. i.e., If defining variables made your code slower and it was a problem, then buy a faster machine. There is something better to be gained than a few CPU cycles in *this* case: human time tracking down bugs. If micro performance is a real concern (sometimes it can be), then don't use PHP. – Matthew Mar 17 '11 at 20:42
3

Will this affect system performance by any chance.

Yes.

But you should declare all variables and indexes before using them because the next time you misspell a variable name, you will notice the mistake immediately, instead of it getting lost in the noise.

The time you save tracking down such a silly bug can then be used to code something important, like a more optimized algorithm that will save even more time.

This indirect "system performance gain" is of more value than the direct saving.

So i declare and assign somany variable and if i am not using those variables . Will this affect the performance.

Failing to declare your variables doesn't change the number that you actually are using! Declare them at the appropriate place. Keep your scopes limited to the task at hand, and it will be easy to manage.

Matthew
  • 47,584
  • 11
  • 86
  • 98
1

Logging always causes a small overhead and if you can avoid unneeded error logging with little work, why not do it? It won't affect system performance dramatically, but imho it's generally not desirable to clutter your log space with warnings for undefined variables.

If you fill your logs with stuff like this, the real errors will be much more difficult to spot.

Another doubt is , in some cases those variables will not be using.

Declare them as soon as you know that you need them. There is no need to have all your variables declared at the beginning of the script ...

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122