Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old July 17th, 2005, 03:15 PM
mydejamail@yahoo.co.uk
Guest
 
Posts: n/a
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

  #2  
Old July 17th, 2005, 03:15 PM
Chris Hope
Guest
 
Posts: n/a

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


mydejamail@yahoo.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
  #3  
Old July 18th, 2005, 09:35 AM
Colin McKinnon
Guest
 
Posts: n/a

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


mydejamail@yahoo.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.
  #4  
Old July 21st, 2005, 07:55 AM
mydejamail@yahoo.co.uk
Guest
 
Posts: n/a

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


Are there any examples of the above techniques?

  #5  
Old July 21st, 2005, 07:56 AM
cyberhorse
Guest
 
Posts: n/a

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.

  #6  
Old July 21st, 2005, 07:56 AM
cyberhorse
Guest
 
Posts: n/a

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.

Closed Thread