2009/5/23 Robert Cummings <robert@xxxxxxxxxxxxx>: > On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: >> 2009/5/23 Afan Pasalic <afan@xxxxxxxx>: >> > short hack works like a charm! >> > :-) >> >> It may work but output buffers are relatively expensive. The eval >> function will return the value the eval'd code returns, so just stick >> a return statement at the end of the string you're eval'ing. > > Where di you hear that output buffers are expensive? I have found the > following: > > <?php > > ob_start(); > > for( $i = 0; $i < 10000000; $i++ ) > { > echo 'blaaaaaaaaaaaaaaaaaaaaaaaaaah'; > } > > $foo = ob_get_contents(); > ob_end_clean(); > > ?> > > To consistently be faster than the following: > > <?php > > for( $i = 0; $i < 10000000; $i++ ) > { > $foo .= 'blaaaaaaaaaaaaaaaaaaaaaaaaaah'; > } > > ?> > > However, if I do the following: > > <?php > > for( $i = 0; $i < 10000000; $i++ ) > { > ob_start(); > echo 'blaaaaaaaaaaaaaaaaaaaaaaaaaah'; > $foo .= ob_get_contents(); > ob_end_clean(); > } > > ?> > > The run-time is approximately 3 times slower... not exactly expensive > considering it incorporates the concatenation as well as the output > buffering. Context is everything Rob. I said *relatively* expensive because the comparison was between using an output buffer to capture a value from a call to eval compared to simply returning the value from the eval'd code. Context. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php