Is there a setting or program for doing strict checking in PHP compilation?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mydejamail@yahoo.co.uk

    Is there a setting or program for doing strict checking in PHP compilation?

    Coming from an objectpascal background with strict type checking, I am
    being driven nuts by PHP.

    Stuff like using variables without declaring them, case sensitivity of
    variables, getting true, false, 0, 1, "" mixed up, missing the $ before
    variables etc is really slowing me down.

    Is there a way to configure a run-time setting or interpreter setting
    that will throw up warnings or declare an error if some of these issues
    are present?

    I really need an external lint type program or a run-time setting that
    will highlight these issues in PHP.

    /My

  • Chris Hope

    #2
    Re: Is there a setting or program for doing strict checking in PHP compilation?

    mydejamail@yaho o.co.uk wrote:
    [color=blue]
    > Coming from an objectpascal background with strict type checking, I am
    > being driven nuts by PHP.
    >
    > Stuff like using variables without declaring them, case sensitivity of
    > variables, getting true, false, 0, 1, "" mixed up, missing the $
    > before variables etc is really slowing me down.
    >
    > Is there a way to configure a run-time setting or interpreter setting
    > that will throw up warnings or declare an error if some of these
    > issues are present?
    >
    > I really need an external lint type program or a run-time setting that
    > will highlight these issues in PHP.[/color]

    Use === for a strict type checked comparison, and error_reporting (15) to
    get the other stuff (or change the setting in your local php.ini or
    httpd.conf files).

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

    Comment

    • Colin McKinnon

      #3
      Re: Is there a setting or program for doing strict checking in PHP compilation?

      mydejamail@yaho o.co.uk wrote:
      [color=blue]
      > Stuff like using variables without declaring them, case sensitivity of
      > variables, getting true, false, 0, 1, "" mixed up, missing the $ before
      > variables etc is really slowing me down.
      >
      > Is there a way to configure a run-time setting or interpreter setting
      > that will throw up warnings or declare an error if some of these issues
      > are present?
      >
      > I really need an external lint type program or a run-time setting that
      > will highlight these issues in PHP.
      >[/color]

      uninitialized variables will produce a 'NOTICE' exception. Solution would be
      to specif error reporting (only) at the start of each script. Set to E_ALL
      for testing, something less sensitive for production. Or write your own
      error handler.

      C.

      Comment

      • mydejamail@yahoo.co.uk

        #4
        Re: Is there a setting or program for doing strict checking in PHP compilation?

        Are there any examples of the above techniques?

        Comment

        • cyberhorse

          #5
          Re: Is there a setting or program for doing strict checking in PHP compilation?

          At the beginning of your code, do this:

          error_reporting (E_ALL);

          when you check if a variable is false, rather than empty, to this:

          if (flag === false)

          if you want to check if something is storing an integer, you can do
          type checking with:
          is_integer(i) or is_int(i)

          for the $ - your editor should help you identify these. I would
          recommend PHP Eclipse.

          Comment

          • cyberhorse

            #6
            Re: Is there a setting or program for doing strict checking in PHP compilation?

            talking about $, I missed it in all my examples, grrrr
            flag should be $flag and i should be $i - sorry about that ... been
            programming too much in other languages lately.

            Comment

            Working...