Просмотр поста

.
Screamer

есть небольшой класс

class template {
    public static $template;
    private static $errors = array();

    static function insert_block() {
        preg_match_all('/(<block=")([\w]+)("\/>)/', self::$template, $blocks);
        if (!empty($blocks)) {
            $blocks = $blocks[2];
            foreach ($blocks as $key => $name) {
                if (file_exists($name . '.tpl')) {
                    $file = file_get_contents($name . '.tpl');
                    self::$template = str_replace('<block="' . $name . '"/>', $file , self::$template);
                } else {
                    self::$errors[] = 'Block ' . $name . '.tpl is not exists';
                }
            }
            if (preg_match('/(<block=")([\w]+)("\/>)/', self::$template)) self::insert_block();
        }
    }

    static function load_tpl($template) {
        self::$template = file_get_contents($template);
        self::insert_block();
        self::display_errors();

    }
    static function display_errors() {
        if (!empty(self::$errors)) die (implode('<br />', self::$errors));
    }
}
template::load_tpl('index.tpl');
echo template::$template;

После непродолжительной работы вот что вылетает
Fatal error: Maximum function nesting level of '100' reached, aborting! in W:\html\temp\www\index.php on line 11

Как можно от этого избавится кроме отказа от рекурсии