Re: critique this code please

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

 



* Thus wrote Nigel Jones:
> I personally don't see anything wrong with it.  It's actually better
> than any of my attempts to do templating.

There are a  lot of things with the system, imo, i just stopped at
the point where I read:

  eval('echo "'. template($foo) . '")');

all that evaluates to is a simple:

  include(template_filename($foo));

Without the overhead of:

  eval() - wich is know to be the slowest method to execute code
  echo() - instead of php  having to go and evaluate a string the
           contents of the files are read directly to the browser 
           on an include.
  template() - a function that goes out and builds a sting and pre
               processes it (side note, Hypertext Preparsing)


The function.phps file has already been evalutate so I'll just
point out some of the points for that file.

  - no need for the globals, use static for the $templatecache
    and pass a parameter to the function template to be verbose or
    not (aka $setting['debugtemplate'])

    * this will provide for a cleaner and more isolated function.

  - use isset($templatecache[$templatename]) instead
    
    * prevents unnescesary E_NOTICE errors

  - the use of file_get_contents is much prefered over opening a
    file handle, etc.  Althogh file_get_contents() requires >=
    4.3.0, php should be upgraded anyway.

    * file_get_contents is known to be much faster and efficient
      than the other alternatives


  - overuse of addslashes then stripping them down, using
    str_replace with the first two parameters as array's to
    specifiy what needs to get cleaned up.

    * just too much overhead.


One major point that should be noted is that php *is* a templating
system already, so re-creating somthing like this is not really
necessary.

If caching is a desired thing, for starters the filesystem will
already do caching on recently accessed files, so OS level
optimizations can be done.  Also you can use things like APC
(http://pecl.php.net/package/APC).

  
> 
> BTW Curt: Check your clock/s, it seems to be a day out.

Thanks for the heads up on this.

 

Curt
-- 
Quoth the Raven, "Nevermore."

-- 
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