Re: How to assign eval() to variable?

From: Date: Sat, 23 May 2009 14:34:00 +0000
Subject: Re: How to assign eval() to variable?
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-293024@lists.php.net to get a copy of this message
2009/5/23 Robert Cummings <robert@interjinn.com>: > On Sat, 2009-05-23 at 15:11 +0100, Stuart wrote: >> 2009/5/23 Robert Cummings <robert@interjinn.com>: >> > 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. >> >> 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. > > You should have connected your phrasing to context then. Your wording > suggested a generalization. "Relatively expensive" did not relate to any > other information you provided in the same sentence... relatively > expensive to what? It was in the first sentence, before you introduced > information about returning directly from the eval statement. > Information linkage is important, as is chronology. Looking back at what I wrote I agree that I could have made it clearer. The context I was relying on from the message I was replying to did not adequately frame my comment. -Stuart -- http://stut.net/

« previous php.general (#293024) next »