Re: [PHP] getStatic

2008-11-30 Thread Craige Leeder

Yeti wrote:

I think PHP's string functions are pretty fast and even with large
documents we are talking about a couple of extra microseconds on a
modern machine. I once saw someone do pretty much the same as you are
trying to do with strtr() [1], but I don't know if that function is
faster than str_replace(). You should also consider that if you
framework is going to manage someone's site one day then it could
possibly be on a server with an older PHP version. I disagree with
those on the list saying one should just stick to an existing
templating framework, since it can be quite exciting to think some
neat thingy out. Of course, most people (including me) hardly have any
time at all to spend 1000s of hours on a more or less private project.

[1] http://in.php.net/manual/en/function.strtr.php

  



Hey Yeti,

Sorry I took so long to respond. Been a busy week or so.

I've decided, for ease of production, to go another route. I am for the 
time being, using Smarty's engine. This will likely change down the road 
to a custom template engine, but I believe at this time this is the best 
option in regards to time/ease.


Thanks for the help anyways. It was valuable information.

- Craige

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



Re: [PHP] getStatic

2008-11-25 Thread ceo

str_replace will take arrays for before and after sequences.



So, build arrays, and do ONE str_replace and Bob's your uncle.



Another option, a bit crude, but effective, would be to wrap your template-y 
bit in a function that calls 'extract' on an array of variable names.



class Template_thingie {



private $vars = array();



public function template_register_variable($varname){

  $vars[] = $varname;

}



function template_render_whatsit(){

  extract($vars);

  include(some_file_$foo_here.php);

}

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



[PHP] getStatic

2008-11-24 Thread Craige Leeder

Hey guys,

So, I was working on my framework today, and noticed unfortunately that 
PHP does not allow using the magic method __get for static variables. 
There is a patch available, but I'm not sure how long it will be before 
it makes it into the stable PHP release.


Anyway, my question is about what route I should take now.

The reason I was looking for this was for the built in template engine. 
I expected to be able to put in a page


{HTML::$variable1}
or
{self::$variable1}

and have it evaluate using native PHP variables, instead of doing a 
large number of PHP str_replace for text based variables, a process 
which is surely slower.


As I see it, my options are:

Create

public static function get($fpName)

And have my templates littered with the extra

{HTML::get(variable1)}

OR

use PHP str_replace based variable parsing creating what I imagine would 
be a significantly higher overhead.


What would you do?

- Craige



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



Re: [PHP] getStatic

2008-11-24 Thread Yeti
 What would you do?

I think PHP's string functions are pretty fast and even with large
documents we are talking about a couple of extra microseconds on a
modern machine. I once saw someone do pretty much the same as you are
trying to do with strtr() [1], but I don't know if that function is
faster than str_replace(). You should also consider that if you
framework is going to manage someone's site one day then it could
possibly be on a server with an older PHP version. I disagree with
those on the list saying one should just stick to an existing
templating framework, since it can be quite exciting to think some
neat thingy out. Of course, most people (including me) hardly have any
time at all to spend 1000s of hours on a more or less private project.

[1] http://in.php.net/manual/en/function.strtr.php

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