I'm looking for a php syntax checker, preferably as an eclipse plugin, preferably be able to sort of compile it(at least find undefined variables in addition to syntax checking. Does such thing exist?
Every better IDE (PhpStorm, Eclipse/PDT, Eclipse/PHPEclipse, Netbeans with PHP-Plugin, and so on) comes with automatic syntax check built-in. At least PhpStorm is able to find undefined variables. The last time I used PDT it didn't support it. PHPEclipse seems to be not maintained anymore, so I assume, that it cannot find undefined variables too, and netbeans ... don't know.
If you just want to check the syntax the quick&dirty way, you can use the php-interpreter itself
php -l filename.php
Of course, look on this:
http://www.eclipse.org/pdt/
This IDE using php parser engine to syntax, and is for free :-).
But, better do not use the plugin version from update site, but All-In-One Package. At least previous versions from update site did not work too well...
Install phpEclipse for syntax-checking:
http://www.phpeclipse.com/
In PHP there is no such thing as an undefined variable. Variables are automatically initialized with null.
Zend Studio (custom Eclipse) also has a syntax checker, FWIW.
Our PHP Formatter parses PHP code to an AST, and then prettyprints the results. This can be used as a command-line script. If the source file isn't parsable, the tool exits with with an error (and doesn't prettyprint). So, if you ignore the prettyprint feature, this is precisely a command-line level syntax checker. Easy to launch from Eclipse.
Related
I'm testing pug-php (with laravel-pug) for use in a future project.
I'm using PHP expression syntax (I prefer it to JS expression syntax), but Pug plugin for PhpStorm is only for JS Syntax.
Can I configure PhpStorm for use PHP syntax and recognize PHP function like strtoupper($str).
This capture show errors and warnings marked by the IDE, but it code compile fine.
There is no support for pug-php in PhpStorm at the moment. We also did not receive any requests for this so it would be great if you could submit the feature request to our tracking system here: http://youtrack.jetbrains.com/issues/WI#newissue=yes.
You will be able to receive the answer directly from our developers while other users will be able to write their opinion of your proposal.
I have done some research but have not found something that fits my scenario exactly. I am using Dreamweaver CS5 with PHP files and Dreamweaver alerts me that there is an error in my code with this line:
if(explode("_","some_variable")[0]=="some"){
If I remove the brackets [ ] then the error message goes away making the line be
if(explode("_","some_variable")=="some"){ //never true obviously
I know that I could assign the exploded array to a variable and then call the first value of that variable to remove this code but I was trying to find a solution to be able to write a little more shorthand code.
I found that this method of calling an index is supported from PHP version 5.4 from the answer here: https://stackoverflow.com/a/19408331/1707323 but Dreamweaver still throws error alert. I was able to find out that Dreamweaver CS5 supports code hinting and syntax for PHP version 5.2.
So the main question is: How can I add more support to Dreamweaver CS5 code hinting and syntax checker OR is there a way to ignore certain syntax errors while preserving the rest of the syntax checker?
I know that I could change the line to
if($string = explode("_",$key) && $string[0]=="understand"){
Or I could write a custom function such as the referred answer above suggests, but why write extra code just to satisfy an outdated syntax checker when there might be a way to update the syntax checker.
Note: I am not looking for any answers that involves updating to a newer version of Dreamweaver such as CS5.5 or CS6 as I already have CS5 and do not want to dish out money just for this reason.
The short answer is you can't extend code syntax for CS5. Adobe doesn't support older versions of Dreamweaver and there will not be a patch for it. They want you to upgrade to the latest (subscription-based) version instead.
in dreamweaver cc 2015, your code still alert in the info bar as an error.
dreamweaver use a PHP_KnowledgeEngine.dll (in it's configration folder), it seems this engine is using some source code fron zend engine, but it still cannot correcttly handle this situation.
Dreamweaver has been my favourite IDE for programming PHP for a while.
However we have recently updated our servers to work with php 5.3.x
Now everytime I use php 5.3 specific tags like namespace dreamweaver suggests that there is a syntax error.
I would like to be able to add the namespace as a valid tag or install a plugin which does that for me. If that can't be done it would be best if I could just disable the checking for errors.
Can anyone help me out?
Thanks in advance!
Dreamweaver CS5 PHP support is limited to PHP 5.2 (based on a couple of Google searches), and the syntax checker is not extensible, so no extension would be able to make that go away. I've seen in a couple of places that you can turn off the error checking by turning off the PHP related code hints (Edit [Dreamweaver on Mac] -> Preferences -> Code Hints), but I've not tried that. Of course, if that works, then you'll get no code hints for variables and functions defined in your code, so not sure that will be a good trade off. On the other hand, Dreamweaver does report that code hinting may not work until syntax errors are corrected.
Dreamweaver CS5.5 Dynamic Code HInting PHP support is updated to PHP 5.3
Is it possible to check syntax of php-code (without running),
similar to the
php-cli -l
when running php the "ordinary" way (as a module)?
There are also some PECL extensions which parse PHP code for various reasons. First there is BCompiler, which can compile a PHP into byte code. Since this step requires parsing the PHP code, I would expect errors if it isn't lint. Parsekit allwos you to compile PHP code to OP codes, which is basically what you desire. However, the extension did not have a release since late 2009, so it might be outdated. Parse_Tree is sadly unmaintained since 2007, but its purpose is to parse a PHP file into an AST. Maybe you can get to something with this one, after some polishing.
PHP_Parser is a PEAR package, which does not rely on special PHP extensions and attempts to parse PHP code from within PHP. Its marked alpha and unmaintained, but it might give you a basis to experiment with.
You can try to run a tool like PHP Depend on the sources, which attempts to parse the given PHP files into an abstract syntax tree. While this might not catch all PHP parser errors, it will already catch quite a lot of them.
You get nice software metrics as an additional goodie, if the code is valid. :)
Is it possible to check syntax of php-code (without running), similar to the php-cli -l
when running php the "ordinary" way (as a module)?
I think the question everyone missed is that there is no difference in PHP syntax whether you run it as a module, or simply execute the binary from a shell: the PHP syntax is the same on both occasions. So, you might as well just use php -l filename.php, as that has the exact same result as using the tools listed above.
For getting the same result as php-cli -l, use the function: php_check_syntax
I've been using xdebug to debug and understand code in php projects for a while now, and have sometimes come into situations where it's been unclear what's going on inside of PHP.
Is it possible to set xdebug or gdb up so that i can trace into actual php builtin functions?
If you are using a macosx, solaris or recent freebsd system you can throw a little dtrace at it. It can come in handy for those all too numerous "WTF is PHP doing?" moments.
I doubt it, xdebug is intended for tracing your PHP code, not the internals. The internals are assumed to be bug-free (which obviously they aren't sometimes, but that's beyond the scope of xdebug).
You can always look at the PHP source if you want to know what the built-in functions do, but that's sometimes pretty hairy. The PHP manual docs have always served me well enough when I want to know what they'll do.
You can use gdb to trace in to the C-level code, provided you have php compiled with debug symbols. Have a look here for a start:
http://derickrethans.nl/phps_segmentation_faults_gdbfu.php
One way to test the output of the Zend engine, to peek inside at the opcodes, you can use Derick Rethan's VLD (Vulcan Logic Dissasembler), which also appears to be on PECL. Note: only works on *nix systems (see site for requirements).
Some examples of debugging these opcodes can be found on Sara Golemon's blog, in articles such as Understanding Opcodes and How long is a piece of string?.
There is also great Google Chrome extension PHP Console with php library that allows to:
See errors & exception in Chrome JavaScript console & in notification popups.
Dump any type variable.
Execute PHP code remotely.
Protect access by password.
Group console logs by request.
Jump to error file:line in your text editor.
Copy error/debug data to clipboard (for testers).
Recommend to everyone!