Re: How PHP handles multiple inclusions of the same file?
| From: | Justin Patrin | Date: | Mon, 09 Aug 2004 21:27:05 +0000 |
| Subject: | Re: How PHP handles multiple inclusions of the same file? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193227@lists.php.net to get a copy of this message | ||
On Mon, 9 Aug 2004 15:14:57 -0400, John W. Holmes
<holmes072000@charter.net> wrote:
> From: "Justin Patrin" <papercrane@gmail.com>
> > > eval($script);
> > > use_cached_code();
> >
> > Ick! eval() is evil!
>
> You have benchmarks to back that up or experience?
>
Well, I didn't mean speed-wise necessarily, although it means more
parsing. Much better to use a *function* which is parsed once than
include()ing or eval()ing the same code over and over to (possibly) be
re-parsed. It just makes more sense code structure-wise as well.
> I did a benchmark between using include(), eval(), smarty, pattemplate, and
> a few others and include() and eval() are always the fastest.
>
> Really depends upon what kind of features you need and what you consider
> "evil". ;)
By evil I mean that it's used for the wrong purposes much of the time.
People aren't aware of the capabilities of the language or are simply
ignorant of good coding style and use eval because it's easy. Heck, I
used eval before I knew how to use $$ and arrays effectively. Here's a
quote that really says it well:
If eval() is the answer, you're almost certainly asking the wrong question.
-- Rasmus Lerdorf, BDFL of PHP
>
> ---John Holmes...
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--