Fusebox has a few requirements of the languages it runs on. Dynamic includes is one we discussed earlier, but another is output buffering. ColdFusion Fusebox developers have historically had the benefit of Steve Nelson's CF_BodyContent custom tag, and with ColdFusion 5, now have CFSaveContent (really the same thing, but without credit being given to Steve).
PHP3 had no way to buffer output to a variable the way CF_BodyContent and CFSaveContent can, but with PHP4, a set of output buffering functions were added, making PHP-Fusebox far more attainable. I have encapsulated those functions an a class I first called (wait for it...) BodyContent! With the revamping I gave the BodyContent class for Fusebox 3.0, I have now changed the name to (you guessed it...) SaveContent. Both of these versions are available in the downloads section.
So it looks like PHP can do just about everything ColdFusion can do, right? That's actually more or less true, and PHP actually has an impressive set of add-on modules that ColdFusion could not handle without an external COM object or CFX tag things like image manipulation, PDF, Flash, and CyberCash to mention a few. To get a full picture of what I mean, just take a look at the PHP Manual and scroll through the function reference.
But what can PHP not do? Well, custom tags are something that PHP cannot handle. Because PHP relies on the delimiters mentioned earlier (<?php [...] ?>), a tag inline with the rest of the HTML would not get interpreted by PHP.
However, another piece of the custom tag puzzle is that code running within a custom tag is running in its own namespace. This concept came up before when we were discussing CFModule, and for a good reason calling a template via CFModule is the same as calling a ColdFusion custom tag.
PHP does not have the plethora of built-in variable scopes that ColdFusion comes with, but there is a way to create a protected space for variables via custom classes. With the release of Fusebox 3.0 for PHP, I monkeyed around with the new SaveContent class, and found a way to mimic the functionality of CFModule in PHP! I also abstracted the call a bit to simplify coding. You call the function like this:
The code in "foo.php" will now run in a safe namespace, and the variables passed in will be available to "foo.php" in the $attributes associative array: $attributes["var"] is set to "value", and $attributes["stan"] is set to "cox".