Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
mydejamail@yahoo.co.uk
Guest
 
Posts: n/a
Default 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


  #2  
Old July 17th, 2005, 02:15 PM
Chris Hope
Guest
 
Posts: n/a
Default 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, 08:35 AM
Colin McKinnon
Guest
 
Posts: n/a
Default 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, 06:55 AM
mydejamail@yahoo.co.uk
Guest
 
Posts: n/a
Default 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, 06:56 AM
cyberhorse
Guest
 
Posts: n/a
Default 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, 06:56 AM
cyberhorse
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.