PHP Lexical and Syntax analyzer written in C/C++ - php

I'm writing a PHP IDE in Qt4 for my Master's project. I am trying to duplicate a lot of the functionality of Eclipse or Visual Studio without all the bloat and the overhead. I'm trying to do some code completion but I need to do some syntax analyzing to have intelligent code completion. I've looked at the PHP source code and thought about just compiling the Zend engine in my code (and give credit where credit is due), but even after staring at the code for a couple of days I'm not sure where to start with that.
Does anyone know some C++ code that already accomplishes this, or have used the Zend engine for their own purposes, or have some advice about writing my own?

PHP does not have anything even remotely close to a formal LALR(1) or LL(k) grammar that you could use to implement this in a manner suitable for academia. Zend's parser is not context-aware and is full of ad-hoc disambiguations from what I've seen.
That is not to say you cannot write something that does simple syntax highlighting. Take for example this javascript implementation. The code for their tokenizer is here and an active thread about the project is here.

Related

Interface and interpreted language

I'm discovering Php and it's Oop implementation and wondering if there is really an practical utility of using Interfaces when we use a non compiled language and when errors can only be discovered at execution time. Am in missing someting?. Another point is that I didn't find any extension or plugin for editor or Ide which forced implementing the Interface when creating a class which is for me the essential point because Interface are really useful when working with others and functionals requirements. So that make me thinking that we need to know the contracts of the Interfaces before using them..
I didn't find any satisfying reading about these question and hope someone would give me some clues...
As my Questioning were on the way I can be sure of following the contract implied by an Interface I had a look on the differents Ide or extension (I'm using mainly vscode)and now what I understand is I rely on their functionalitie about continuous code validation. For example Dev Sense PHP tools for Vs Code do the job but normal Php Intelliphense doesn't.
If I don't use an Ide or extension with this code validation I will have executing time errors if I fail to execute the whole Interface contract.

Would it be possible to write a parser generator for the Zend/PHP engine?

Out of curiosity, having been studying a few parser generator libraries (Flex, Bison, ANTLR, some LLVM related stuff), would it be possible to write a new parser generator for a pre-existing scripting language's engine such as PHP? I realize Facebook has basically done it except they wrote a whole new virtual machine to address issues they had with the Zend engine (?).
I've been able to create a few toy compiler examples for compiled VMs such as the JVM by generating the opcodes for a basic syntax and learning a lot of the JVM's class file structures and opcodes.
What intrigues me though is whether it's possible to replace Zend's PHP parser with your own without having to edit the core of the engine.
I ask this simply out of curiosity since I think it'd be an enjoyable little product to try work on some Zend/PHP engine languages that aren't source-to-source.

PHP IDE compiling code on the fly similar to java

I got a question about the IDEs: With Java, you use Netbeans or Eclipse, which are very great IDEs to code. Now, if I do a misspelling, Eclipse reports it immediately with a red line (for example a function call which was misspelled).
As I know, this works with some sort of dummy-compiling on the fly.
Now, why is there no IDE at all which provides the same stuff for PHP? Just a sort of "on the fly-interpreting" which does not really execute all functions, but it interprets the code. It would sometimes make programming much easier. Is this possible at all? If no, why not?
Thanks for response ;)
Flo
The PDT Development Tools plugin for Eclipse does exactly that. Just tell it where your PHP interpreter sits. And keep in mind that it of course can't catch errors that occur at runtime. So it will only report actual syntax errors.

Start compiling PHP extensions

I have code that is straight forward, but intensive. I would like to compile it into a PHP extension. What is the simplest / best practice for going about that?
I have a Java background, so writing the C / C++ code shouldn't be an issue. I would, however, like to avoid any pitfalls along the way.
A simple tutorial or walk through is something I haven't been able to find. Plenty of examples, but nothing aimed at someone new to doing this.
It looks like a more arduous road then I though, especially with all the lovely C quirks.
The PHP Manual and this Zend article seem to cover quite a bit of ground in regards to writing PHP extensions.
The the tag info for php-extension and in particular, this answer, also linked from there.
You should try SWIG for generating wrapper for your source code, and then create your extension. It supports various languages like Java, C/C++ and makes it as simple as possible.

What is the best IDE for PHP? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I'm a PHP developer and now I use Notepad++ for code editing, but lately I've been searching for an IDE to ease my work.
I've looked into Eclipse, Aptana Studio and several others, but I'm not really decided, they all look nice enough but a bit complicated. I'm sure it'll all get easy once I get used to it, but I don't want to waste my time.
This is what I'm looking for:
FTP support
Code highlight
SVN support would be great
Ruby and JavaScript would be great
For PHP I would recommend PhpStorm.
It supports FTP/SFTP synchronization, integrates well with Subversion, CVS, Mercurial and even with Git. Also, it supports HTML, CSS, JavaScript and handles language-mixing well like SQL or HTML blocks inside PHP code, JSON, etc.
But if you need Ruby you can try another IDE - RubyMine with same capabilities but for Ruby.
NetBeans. Check out 7.0.1.
It supports FTP/SFTP synchronization, integrates well with Subversion, CVS, Mercurial and even with Git (with plugin). Also, it supports HTML, CSS, JavaScript, popular frameworks and more.
And its free.
Too bad no one mentioned phpDesigner. It's really the best IDE I've came across (and I believe I've tried them all).
The main pro of this one is that it's NOT Java based. This keeps the whole thing quick.
Features:
Intelligent Syntax Highlighter - automatic switch between PHP, HTML, CSS, and JavaScript depending on your position!
PHP (both version 4 and 5 are supported)
SQL (MySQL, MSSQL 2000, MSSQL 7, Ingres, Interbase 6, Oracle, Sybase)
HTML/XHTML
CSS (both version 1 and 2.1 are supported)
JavaScript
VBScript
Java
C#
Perl
Python
Ruby
Smarty
PHP:
Support for both PHP 4 and PHP 5
Code Explorer for PHP (includes, classes, extended classes, interfaces, properties, functions, constants and variables)
Code Completion (IntelliSense) for PHP - code assist as you type
Code Tip (code hint) for PHP - code assist as you type
Work with any PHP frameworks (access classes, functions, variables, etc. on the fly)
PHP object oriented programming (OOP) including nested objects
Support for PHP heredoc
Enclose strings with single- or double quotes, linefeed, carriage return or tabs
PHP server variables
PHP statement templates (if, else, then, while…)
Powerful PHP Code Beautifier with many configurations and profile support
phpDocumentor wizard
Add phpDocumentor documentation to functions and classes with one click!
phpDocumentor tags
Comment or uncomment with one click!
Jump to any declaration with filtering by classes, interfaces, functions, variables or constants
Debug (PHP):
Debug with Xdebug
Breakpoints
Step by step debugging
Step into
Step over
Run to cursor
Run until return
Call stack
Watches
Context variables
Evaluate
Profiling
Multiple sessions
Evaluation tip
Catch errors
Are you sure you're looking for an IDE? The features you're describing, along with the impression of being too complicated that you got from e.g. Aptana, suggest that perhaps all you really want is a good editor with syntax highlighting and integration with some common workflow tools. For this, there are tons of options.
I've used jEdit on several platforms successfully, and that alone puts it above most of the rest (many of the IDEs are cross-platform too, but Aptana and anything Eclipse-based is going to be pretty heavy-weight, if full-featured). jEdit has ready-made plugins for everything on your list, and syntax highlighting for a wide range of languages. You can also bring up a shell in the bottom of your window, invoke scripts from within the editor, and so forth. It's not perfect (the UI is better than most Java UIs, but not perfect yet I don't think), but I've had good luck with it, and it'll be a hell of a lot simpler than Aptana/Eclipse.
That said, I do like Aptana quite a bit for web development, it does a lot of the grunt work for you once you're over the learning curve.
Eclipse PDT is very nice.
I'm always amazed that more people don't use ActiveState Komodo.
It has the best debugging facilities of any PHP IDE I have tried, is a very mature product and has more useful features than you can shake a stick at. Of note, it has a fantastic HTTP inspector, Javascript debugger and Regular Expression Toolkit. You can get it so that it steps through your PHP, then you see your Javascript running, and then see your HTTP traffic going out over the wire!
It also comes in free (Komodo Edit) and open (OpenKomodo versions).
Oh, and if you don't always hack just on PHP, it's designed as a multi-language editor and rocks for Ruby and Python too.
I've been a happy customer for around 5 years.
There's no "best" IDE, only better and worse ones.
Right now I'm trying to settle in with Aptana. It has a lot of cruft that I don't want, like "Jaxer" doodads all over the place. It's reasonably fast, but chokes on large files when syntax highliting is on. I have not been able to figure out how to set up PHP debugging. Three good things about Aptana: easy plugin installations, very fast and intuitive Subversion plugins, ligning fast file search.
I tried Eclipse PDT and Zend for Eclipse, but they have nightmare levels of interface cruft. Installing plugins is a living horror of version mismatches and cryptic error messages.
I also use Komodo (they bought us licenses at work). Komodo has a very intuitive interface, but is ridiculously slow, chokes on medium sized files with syntax highlighting. File search is intuitive, but rather slow. Subversion integration is not that great - slow and buggy. If not for slowness, I would have probably stuck with Komodo, especially for the debugger.
To get you started, here is a list of PHP Editors (Wikipedia).
For PHP in particular, PHPEdit is the best, and I tried and worked in some of them including, Dreamweaver, Elipse, Emacs, Notepad++, NetBeans, UltraEdit ...
Geany is a great lightweight editor -- like Notepad++ for Linux, only better. I find this, combined with a few shell scripts and symlinks for linking modules into a web source tree, make developing on Linux easy and fun.
I love JetBrains IDEs. For PHP it is JetBrains PHPStorm.
http://www.ibm.com/developerworks/opensource/library/os-php-ide/index.html
Personally, I love Notepad++... :D . The above link compares some of the better IDEs and the best ones aren't free.
I'd recommend Komodo 4.4 though (I used the trial version) since it was awesome. Better than Notepad++, but not free... :(
I would recommend Zend IDE for the integrated debugger.
I'm using Zend Studio. It has decent syntax highlighting, code completion and such. But the best part is that you can debug PHP code, either with a standalone PHP interpreter, or even on a live web server as you "browse" along your pages. You get the usual Visual Studio keys, breakpoints, watches and call stack, which is almost indispensable for bug hunting. No more "alert()"-cluttered debugged source code :)
Have you looked at Delphi for PHP (<http://www.codegear.com/products/delphi/php>) ?
Joe Stagner of Microsoft really likes Delphi for PHP.
He says it here: "[Delphi for PHP] 2.0 is the REAL DEAL and I LOVE IT !"
Eclipse with PDT.
I use and like Rapid PHP.
What features of an IDE do you want? Integrated build engine? Debugger? Code highlighting? IntelliSense? Project management? Configuration management? Testing tools? Except for code highlighting, none of these are in your requirements.
So my suggestion is to use an editor that supports plugins, like Notepad++ (which you are already used to). If there's not already a plugin that does what you want, then write one.
I use Coda on Mac OS X.
There is a new guy in town, PhpStorm from JetBrains. You use it and I bet you will forget all the other editors. It's bit pricey though, unfortunately.
RadPHP (previously known as Delphi for PHP) is the best.
All are good, but only Delphi for PHP (RadPHP 3.0) has a designer, drag and drop controls, GUI editeor, huge set of components including Zend Framework, Facebook, database, etc. components. It is the best in town.
RadPHP is the best of all; It has all the features the others have. Its designer is the best of all. You can design your page just like Dreamweaver (more than Dreamweaver).
If you use RadPHP you will feel like using ASP.NET with Visual Studio (but the language is PHP).
It's too bad only a few know about this.
Aptana supports this and I use it for all of my web development now.
Hands down the best IDE for PHP is NuSphere PHPEd. It's a no contest. It is so good that I use WINE to run it on my Mac. PHPEd has an awesome debugger built into it that can be used with their local webserver (totally automatic) or you can just install the dbg module for XAMPP or any other Apache you want to run.
The best IDE for PHP in my opinion is Zend Studio (which itself is based on Eclipse PDT). Note that in this case "best" does not necessarily mean "good." It is slow and a bit buggy, but even so, it's still the best option for PHP programmers. I've tried a ton of PHP editors over the years and I haven't yet found one that works great.
Komodo IDE would be my second choice. My only problem with Komodo is that the autocomplete is not as good. With properly structured apps where you use phpDoc to document return types etc., it should be alright. But I work on a project that doesn't really do that and Komodo can't read across files to know that $user is a User object for example.
Personally everything that is based uppon Eclipse or NetBeans is an overkill, the GUI is crap and the performance is soooo slow compared to other alternatives.
If you're willing to pay I would suggest Zend IDE (version 5.5, not 6 because it's based on Eclipse) and EditPlus for a more lightweight yet powerfull code editor.
If you're looking for free alternatives, or if you code in other languages other than PHP, OpenKomodo is a really nice IDE with almost all the features (no SVN neither CVS) that you require, the only con I see about OpenKomodo is that sometimes it messes my code indentation, but then again I don't use it on a very regular basis.
As for a free lightweight alternative: Notepad++. =)
My personal preference is Eclipse (with various plug-ins) as I am developing in several languages (PHP, Java, and Ruby) and this way I am always used to interface and keyboard shortcuts. This is not a minor thing as you become very productive this way.
I haven't used Aptana, but will (hopefully) soon - it does look interesting, though.
For others IDEs I have used: jEdit (for little Java), Notepad++ (still for some scripting and short test code runs).
And for the features You asked: Eclipse support many source code version servers (Subclipse); your project can be on a Samba share; ZendDebugger/xdebug for debugging.
I've tried Eclipse PDT, with some success. Aptana is also pretty good, or if you are doing a lot of AJAX stuff, it's great. Your mileage may vary, however, depending on what additional plugins you want to use with them.
PHPEclipse is as close to Eclipse java power as it could get. Eclipse PDT is much weaker (last time I checked).
I'm using PHPDesigner but I will go for Eclipse PDT. I was always against Eclipse until few months ago when I have one Java project to finish... Great IDE
Now I can't imagine one day without Eclipse. :)
Have you tried NetBeans 6? Zend Studio and NetBeans 6 are the best IDEs with PHP support you'll come across and NetBeans is free.

Categories