Re: How to assign eval() to variable?

From: Date: Sat, 23 May 2009 14:07:52 +0000
Subject: Re: How to assign eval() to variable?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-293020@lists.php.net to get a copy of this message
On Sat, 2009-05-23 at 14:43 +0100, Stuart wrote: > 2009/5/23 Afan Pasalic <afan@afan.net>: > > 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. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#293020) next »