Adding new extensions to Zend Studio

I am using Zend Studio for my everyday PHP work, and I like it. I know many others do too, or use PDT. It has one very cool – though not widely known – feature that allows you you to add unknown extensions to code completion. I.e., if you have some extension, create stub file with PHPDOC descriptions – i.e. something like this:

/**
 * Do stuff
 * @param string $arg
 * @return array
 */
 function dostuff($arg) {}

for each extension function, Studio will know to pick it up. You can put this file into Studio’s prototypes directory – easiest way to find it is just write something like chdir() anywhere, select the name and press F3, the directory of the file that you’ll get is the one you need.

However, the problem is how to create this file. E.g., I’m doing some work with MongoDB lately, and PHP has great Mongo extension – which Studio doesn’t know yet. So how do I create those stubs? Obviously, I am too lazy to manually write them. I went to look for a tool that would allow me to make one – and found none. At least not in 15 minutes I spent looking, so I decided to write my own.

What came out is the Reflector. It uses PHP reflection and PHP’s manual XML sources in order to generate stub file (see example mongo.php on git to check what comes out). Right now it’s not very smart and handles only classes/methods, not functions (probably will fix that soon), but maybe it will be useful to somebody.

Or maybe somebody points me to a tool that does that even better in comments 🙂

Update: Roy Ganor (who is leading the Zend Studio project) in comments pointed me to the source of the Studio generator script. It will generate stubs for all extensions you have, as I can see. Try it out. Thanks, Roy!