Re: How to assign eval() to variable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2009-05-23 at 15:11 +0100, Stuart wrote:
> 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.

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.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux