JsLint for PHP anyone?

Anyone with excess time and skill on their hands? Would be awesome to see a port of jslint to PHP (and Perl / Python / Ruby for that matter). There’s probably some issues with multibyte strings to contend with but browsing the source it looks doable.

It would mean is tools like Simple Test could help validate Javascript on a page they’re. Simple Test comes with it’s own regex-based parsing tools, which I introduced briefly here. Whether regexes are the right way to go though is another question, bearing in mind character encoding issues.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • SB

    Okay, JavaScript. But it would be even cooler to have a lint-y thing for PHP, like pychecker for Python, http://pychecker.sourceforge.net/

    Anyone up to it, or is there already such a thing?

  • http://nathanwwong.com someonewhois

    Kinda cool.. wouldn’t be easy to do.

  • Davey

    Okay, JavaScript. But it would be even cooler to have a lint-y thing for PHP, like pychecker for Python, http://pychecker.sourceforge.net/

    Anyone up to it, or is there already such a thing?

    Since PHP4, there has been the -l (thats a lower case L) flag for the PHP binary, L standing for Lint, it’ll find parse errors.

    In PHP5, there is the nice userland function php_check_syntax() [http://www.php.net/manual/en/function.php-check-syntax.php]

    - Davey

  • http://www.realityedge.com.au mrsmiley

    Why would you want to go to the trouble of creating a checker for PHP? PHP comes with a syntax checker built in…

    php -l filename.php

    (that’s a lowercase L by the way). The CLI version has a lint command built into it. If you want to create a web based interface for something like SimpleTest, all you need to do is run it as a system command to check for errors.

    A multi-language lint would be better. Seeing as php scripts can contain js, php, html, xml, etc, you’d really want the lint check to be able to detect which language it is parsing at the time. I think I’ll just chuck that idea in the too hard basket though.

  • http://www.realityedge.com.au mrsmiley

    I’m willing to give it a go when I find some spare time. Good chance for me to finally look at some of the strange OO syntax for JS in a bit more detail.

  • http://www.realityedge.com.au mrsmiley

    I was refering to the jslint port, not the uberlint I hinted at before.

  • http://www.phppatterns.com HarryF

    There’s a new function in PHP: php_check_syntax.

  • Azmo

    php_check_syntax still has a bug, though. It executes the code as well as checking it, so any errors will still… cause errors.

  • Danno

    The php -l is also buggy.
    For example if you have:

    It will return that the syntax is ok. But when you execute that you get the error.