tags:

views:

1047

answers:

4

What ways are there to validate PHP code? I have tried the PHPEclipse plugin which works well but I would like to use a web-based one which is easier to access and use if there is any or maybe a smaller application.

Ideas, tips, hints anyone?

A: 

What type of validation are you after? Easiest way to see if a php page works is just to run it :-)

Simon Groenewolt
+4  A: 

I'm not 100% sure what you're wanting, but you may want to review the answers to this question ... and, of course, you know about using -l (el) option from the command line to check syntax, right?

PTBNL
+2  A: 

PHP actually has some built-in methods that you can use.

There is a function called runkit_lint() in the runkit package that you can use to validate a string of code. You can also use PHP from the command line with the -l option to syntax check a php file:

php -l /path/to/file.php
zombat
A: 

As others have said, this depends on exactly what kind of validation you want to do. If you want to check for syntax errors, there are online resources, such as http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/. I'd also look at the php command, which might have an option to parse a file without running it. If you're looking for some kind of runtime correctness, then you'll have to be a lot more specific as to what you want. It's fundamentally impossible to verify the type correctness of a PHP program without running it, for example.

Just be glad you're not using Perl -- even parsing Perl is not decidable in the general case. ^_^

Thom Smith