I am a big fan of TextMate and I am still learning to leverage its features, even after using it for over two years. I have started writing more “commands” to speed up my development process. I love that I can write commands in PHP that run locally on my Mac, and I still have access to all of the environment variables that TextMate passes such as the current line’s value or the document type and name.
The Problem
I recently upgraded to Snow Leopard, and as a result, upgraded to PHP 5.3 on my local development machine. I have been really impressed with the new features of 5.3, and I am happy it came packed with my OS X install. However, I noticed that a few of my commands had stopped functioning correctly.
I hadn’t had a chance to investigate the problem, but when I sat down to write a new command the other day, I figured it out. The $_ENV variable is an empty array on a default Snow Leopard install. When running PHP from the command line, this global variable holds all of the data about the environment PHP is running in. It’s also how TextMate injects it’s variables into the PHP script.
The Solution
Fortunately, it’s a very easy problem to solve.
1. Open your php.ini file
mate /etc/php.ini
2. Find the directive for variables_order.
The ini file describes this setting:
This directive determines which super global arrays are registered when PHP starts up. [...] G,P,C,E & S are abbreviations for the following respective super globals: GET, POST, COOKIE, ENV and SERVER.
You can read more about the variables_order directive in the php manual
Although the ini claims that the default value is EGPCS, my default ini has GPCS
3. Add an “E” to the beginning of the directive.
variables_order = "EGPCS"
Save and close the file. Your PHP Textmate commands and any other scripts running from the command line should now have the properly populated $_ENV values.
Additional Resources on using PHP for TextMate Commands
- David Walsh Blog Create Commands in TextMate Using PHP
- Stuart Colville Using PHP CLI for TextMate commands
- Ciarán Walsh’s Blog TextMate Tip – Using PHP for Commands
You’re a ninja.
Nice, thanks! Upgraded and thought, “argh, what now!”…at least this was an easy fix.