Announcement

Collapse
No announcement yet.

strict in php?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • strict in php?

    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:
    Code:
    $variable = 0;
    or
    Code:
    $variable = "";
    (btw, this is not a newbie question, I know you don't have to declare them )

  • #2
    No, PHP does not support the "use strict" that Perl does. If you want to declare your variables, you can if you want:
    Code:
    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.
    Matt
    Sybase DBA / PHP fanatic
    Sybase v. MySQL v. Oracle | Why I don't like MySQL | Download Sybase TODAY! | Visit DBForums.com!

    Comment


    • #3
      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.

      Comment


      • #4
        Hmm, a pitty, maybe something for php5

        Thanks anyways

        Comment


        • #5
          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...

          Comment


          • #6
            ok, thanks Matt (who appears to be everywhere too )

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X