SubClosure

{ Don't Repeat Yourself ! }

Browsing Posts published in April, 2009

In order to read the direct output of a PHP script into a variable for later processing
it needs to be buffered.

a buffer can be started with:
ob_start();

then anything that would output data directly can be executed, for example:
include 'foo.php' ; ( which might contain something like: echo 'bar' ; )

then read the buffer into a variable:
$buffer= ob_get_contents();

and clean the buffer afterwards:
ob_end_clean();

That’s it. Now whatever foo.php was outputting is now stored in
$buffer for further processing.

especially useful when implementing templates with PHP.

With this quick line of code it’s possible to convert arrays into anonymous objects in PHP

$obj = (object) array('foo' => 'bar', 'property' => 'value');

This is actually quite useful when using Zend AMF to transfer objects from PHP to Flex or Flash,
without having to create classes for them.

Get Adobe Flash player