Sublime Forum

Php syntax checker, php build

#1

Is in Sublime editor php syntax checker? can this function be done somehow? Can it be done with setting up new build option and if so, how to do that?

Thanks!

0 Likes

#2

I’m 99.9% sure it can be done via a plugin, as long as php is installed in your system, a quick php -l or something would take care of it… now it would be the bomb if we could manipulate the squiggly red lines you get when a word is mispelled thru the API so we can mark the error like zend studio does but I’m afraid that’s not possible right now!

So yes It can be done (I believe so), it’s been on my TODO list for a while :smiley: maybe I should start coding it >.<

I haven’t messed around with build files so it could work with that too :smiley:

0 Likes

#3

Would be cool if Sublime would make check before save, so it will prevent you from saving script with mistakes.

0 Likes

#4

I Agree, but I dont think build mechanism has “build pre save” I know it has “build on save”

0 Likes

#5

Here’s the sublime-build file for PHP

build C:\xampplite\php\php.exe -l "$File" lineNumberRegex ^.*in (.+?) on line ([0-9]*)$

Obviously edit/replace path to php.exe to your specific path. OR you can add php to your PATH enviromental variable and just do a php -l
That should work, now if we get an API to control “spelling” squiggly lines so we can underline the bad lines (or if the build does this by default!) and we get a buildOnPreSave, I think we are good to go! :smiley:

We can even make it syntax check as we type hooking in the onModified event… and put a timeout so it checks every 5 secs or 10s whatever! a la zend studio :smile:

0 Likes

#6

Thanks!

Actually with small change in code in first line you can run php scripts directly in console, change “-l” to “-a”. for more information chech php documentation at php.net/manual/en/features.commandline.php

final code for running php scripts:

build "\xampplite\php\php" -a "$File"
showWhenFinished true

this can be heplfull when you want to check and run small scripts, or when you just want to try behaviour of particular function(s)

0 Likes

#7

[quote=“roman”]Thanks!

Actually with small change in code in first line you can run php scripts directly in console, change “-l” to “-a”. for more information chech php documentation at php.net/manual/en/features.commandline.php

final code for running php scripts:

build "\xampplite\php\php" -a "$File"
showWhenFinished true

this can be heplfull when you want to check and run small scripts, or when you just want to try behaviour of particular function(s)[/quote]

True that! thx for the addition :smile:

0 Likes

#8

I am wanting to run the example code

build "\xampplite\php\php" -a "$File" showWhenFinished true

I went to
Tools -> Build System -> New Build System

which creates a file with

{ "cmd": "make"] }

I saved it as php.sublime-build

It now shows up in Tools -> Build System as “php” so I select it.

I just need to know what I should save in this file, I tried…

build "\xampplite\php\php" -a "$File" showWhenFinished true

But that gives errors when I try to build any file…please help

0 Likes

#9

The SublimeLinter plugin does php syntax checking.

github.com/Kronuz/SublimeLinter, or install with the package_control plugin.

0 Likes

#10

[quote=“jasondavis”]I am wanting to run the example code
But that gives errors when I try to build any file…please help[/quote]

Maybe it’s too old theme, but i beleve i’ll help someone )
So the code is

{ "cmd": "C:\\Program Files (x86)\\Zend\\ZendServer\\bin\\php.exe", "-a", "$file"], "selector": "source.php" }

0 Likes

#11

Try the SublimeLinter plugin, it has php syntax checking either interactively, on load/save or on demand.

github.com/Kronuz/SublimeLinter or you can install it via the Package Control plugin.

0 Likes

#12

[quote=“NiPh”]

[quote=“jasondavis”]I am wanting to run the example code
But that gives errors when I try to build any file…please help[/quote]

Maybe it’s too old theme, but i beleve i’ll help someone )
So the code is

{ "cmd": "C:\\Program Files (x86)\\Zend\\ZendServer\\bin\\php.exe", "-a", "$file"], "selector": "source.php" }[/quote]

“cmd”: “C:\Program Files (x86)\Zend\ZendServer\bin\php.exe”, “$file”]

And better to remove -a, because some troubles with autoload begins )

0 Likes