Forum Moderators: coopster

Message Too Old, No Replies

Any way to force implict variable definition etc?

implicit variable definition var php5

         

jezzer300

9:59 am on Jun 10, 2005 (gmt 0)

10+ Year Member



Hi,

A lot of languages you can force implict variable definition, where you must declare your variables at the top of the function/code before it's used. This way you create less bugs using the wrong variable name, which may not crop up until later on.

Can I do this with PHP5?

coopster

1:37 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes. Turn up the error_reporting() [php.net] on your develepment box and you'll find out immediately when a variable has not been declared prior to being used. It works a lot like Perl's taint/strict mode.

jezzer300

1:57 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Thanks, I'll set that now.

coopster

2:00 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You'll probably notice all kinds of new NOTICE errors now. It helps you write cleaner code. You seem to know about these things already though -- excellent.

And next time, I'll spell development correctly ;-)

jezzer300

2:32 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



I almost thought it wasn't working as no new errors were appearing. Lucky for me the code is quite clean!