PDA

View Full Version : strict in php?


Zef Hemel
Sun 28th Jan '01, 2:53pm
I always like the perl strict module (module that forced you to declare variables before you used them, and if they weren't it gave warnings, useful for debugging). But that isn't possible in php is it? Declaring variables cannot be done can it? The best you can do is:
$variable = 0;
or
$variable = "";

(btw, this is not a newbie question, I know you don't have to declare them ;))

MattR
Sun 28th Jan '01, 4:35pm
No, PHP does not support the "use strict" that Perl does. If you want to declare your variables, you can if you want:

settype( $foo, "integer" );


But there is nothing stopping you from creating a variable on the fly -- perhaps look at the output debugging level-- maybe if you set it low enough the compiler may spit out "created $var" or somesuch, but I doubt it.

Mike Sullivan
Sun 28th Jan '01, 4:50pm
error_reporting(15);

Best you're gonna get.
Keep in mind it's a bit style: 1, 2, 4, 8, 16, 32. 16 and 32 are engine level commands, which may do what you want, but I haven't actually tried them.

Zef Hemel
Mon 29th Jan '01, 10:29am
Hmm, a pitty, maybe something for php5 :)

Thanks anyways

Matt@ikonboard
Tue 30th Jan '01, 10:36pm
php doesn't really need to use the 'strict' pragma.

Perl uses it to aid debugging (but then running a debugger version of perl on your local system is more efficient in finding bugs that strict)

The real reason use strict is used is to comply with mod_perl. As mod_perl works in almost the same way that php works (no forking, just one script continuosly running) perl needs to flush all variables set by a previous ivocation of the script. AFAIK mod_php does this automatically.

Having said all that, it does look really wierd not seeing 'my $var = ' .. '; plastered everywhere...

Zef Hemel
Wed 31st Jan '01, 12:18pm
ok, thanks Matt (who appears to be everywhere too ;))