Re: Where to declare Variables



Bobby wrote:
This is like the argument whether HTML code should validate or not. I
already know which will be your side in it. It's a question of choice.
Some people choose to write software that works, others prefer to
follow rules without questioning them. In my opinion both ways can be
right and I wouldn't call someone who doesn't follow my route amateur.

With disabled notices
I wish you good luck for finding errors like this:

$foo = TRUE;
...
if ($Foo) {
...

}

Why the heck you can't find the error? If the case doesn't return
true, obviously your variable isn't set correctly. The first thing
that comes to my mind is to check whether I have declared it. I don't
need a notice to tell me that.


On 9 Май, 01:55, Michael Fesser <neti...@xxxxxx> wrote:
.oO(Bobby)

error_reporting(E_ALL&(~E_NOTICE)) and you'll get rid off unnecessary
notices.
Notices are never unnecessary. They show you that something in your code
is wrong. It can be a real error or just some sloppiness, but it should
be fixed anyway. Good and correct code doesn't throw notices.

("How irresponsible!"). PHP was built with the idea to write
easy and not declare variables.
Correct. But this is not about declaring any variables, but about
initializing them before the first read-access. This not only is good
style, but was a severe security issue on systems with register_globals
enabled. And such systems still exist.

Sure some people will tell you it's
bad practice, but in my opinion they have too much time on hand for
unproductive tasks.
Not really. It's almost trivial to handle.

Only amateurs use such an error_reporting setting. With disabled notices
I wish you good luck for finding errors like this:

$foo = TRUE;
...
if ($Foo) {
...

}

It's just a notice, but even a notice can be an indication of a really
nasty bug. Ignoring them means to write buggy code. The correct setting
on a dev machine is E_ALL or E_ALL|E_STRICT, nothing else.

Micha


For me, my biggest fear like I stated before was that it may be a Notice today that the code works fine. Now if something changes in the future and now it a warning or error, then I have to go back and fix what used to be notices. It is that 'ounce of protection or pound of cure' thing.

Again to each his own, this is just how I choose to code and look at my projects in the future. Others have different reasons and visions, no better, no worse.

Scotty

--
************************************
Remove the "x" from my email address
Scott Johnson
futureshockx@xxxxxxx
************************************
.



Relevant Pages

  • Re: Where to declare Variables
    ... $foo = TRUE; ... easy and not declare variables. ... initializing them before the first read-access. ... The correct setting ...
    (comp.lang.php)
  • Re: How to implement sizeof operator
    ... project i want to implemnent my own sizeof operator function (like ... Hint: macros can declare variables. ... difference between foo and foo, where the first foo was declared using ... No, at compile-time, it can be done in pure ISO C. ...
    (comp.lang.c)
  • Re: Subroutines with &
    ... print foo(); ... In addition to the expected "Howdy", it produces the following warning: ... You could declare the sub above the ... Or, you could forward declare the sub, like this: ...
    (comp.lang.perl.misc)
  • Re: Calling functions declared in an entity
    ... In VHDL it is possible to declare the following entity: ... entity Foo is ... ARCHITECTURE rtl OF ent_item_decl IS ...
    (comp.lang.vhdl)
  • Re: Function declarations & use of static functions
    ... > mainand foo(), respectively defined in main.c and foo.c. ... > declare foo() within main.c so maincould call it? ... int main ... dsk_readSectorin disk.h for external consumers. ...
    (comp.lang.c)