Re: Please help clear up some php error notice issue? [message #180040 is a reply to message #180036] |
Sat, 29 December 2012 09:26 |
M. Strobel
Messages: 386 Registered: December 2011
Karma:
|
Senior Member |
|
|
Am 29.12.2012 04:12, schrieb BobMCT:
> Since upgrading to version 5.4.x I've been seeing a common error
> complaining about undefined variables.
> I know that the E_Notice can be suppressed but I want to eliminate the
> cause as well.
>
> To address this issue I've added statements at the beginning of the
> code to determine if the named variable is set and if not to set it to
> null. This should then satisfy this complaint.
---cut
> So my understanding is that references to any/all of the above defined
> variables should NOT cause that error notice. However, it seems to
> continue.
>
> Without going bonkers would some of you who understand this somewhat
> syntactical issue please try to explain the best way to handle this
> issue so me and I'm sure many, many other php developers can once and
> for all rid outselves of this so common issue?
There is nothing hidden or special about variables: if you use (read) them before
setting (writing to) them, you get a notice.
It is a decision of the PHP makers to give you a notice. Following accepted
programming standards it should give you an error.
How to avoid it? Your development system must display all PHP messages, including
deprecated and notice. From your first line of code there must be no notice/error at all.
Hints: unset variables can hide in templates. They came from initializing variables
in an if branch, and forgetting to do so in the else branch, or there is no else. If
your program detects several "states" with if - elseif, and you think you have
covered all possible cases and need no else branch: write an else branch and put
trigger_error('logical error', E_USER_ERROR) into it, it can save you headaches.
/Str.
|
|
|