Rewriting Registered Globals in XTEMPLATE

I am using the XTemplate class. It uses registered globals. I have to rewrite partof it so it does not use registered globals. Here is the code from XTemplate where it uses registered globals. Does anyone have an answer on how to rewrite this to use not registered globals. Here goes. I guess maybe I do an array. Lets see what you guys say.

Here are the variables.

class XTemplate {

	/**
	 * Properties
	 */

	/**
	 * Raw contents of the template file
	 *
	 * @access public
	 * @var string
	 */
	public $filecontents = '';

	/**
	 * Unparsed blocks
	 *
	 * @access public
	 * @var array
	 */
	public $blocks = array();

	/**
	 * Parsed blocks
	 *
	 * @var unknown_type
	 */
	public $parsed_blocks = array();

	/**
	 * Preparsed blocks (for file includes)
	 *
	 * @access public
	 * @var array
	 */
	public $preparsed_blocks = array();

	/**
	 * Block parsing order for recursive parsing
	 * (Sometimes reverse :)
	 *
	 * @access public
	 * @var array
	 */
	public $block_parse_order = array();

	/**
	 * Store sub-block names
	 * (For fast resetting)
	 *
	 * @access public
	 * @var array
	 */
	public $sub_blocks = array();

	/**
	 * Variables array
	 *
	 * @access public
	 * @var array
	 */
	public $vars = array();

	/**
	 * File variables array
	 *
	 * @access public
	 * @var array
	 */
	public $filevars = array();

	/**
	 * Filevars' parent block
	 *
	 * @access public
	 * @var array
	 */
	public $filevar_parent = array();

	/**
	 * File caching during duration of script
	 * e.g. files only cached to speed {FILE "filename"} repeats
	 *
	 * @access public
	 * @var array
	 */
	public $filecache = array();

	/**
	 * Location of template files
	 *
	 * @access public
	 * @var string
	 */
	public $tpldir = '';

	/**
	 * Filenames lookup table
	 *
	 * @access public
	 * @var null
	 */
	public $files = null;

	/**
	 * Template filename
	 *
	 * @access public
	 * @var string
	 */
	public $filename = '';

	// moved to setup method so uses the tag_start & end_delims
	/**
	 * RegEx for file includes
	 *
	 * "/\{FILE\s*\"([^\"]+)\"\s*\}/m";
	 *
	 * @access public
	 * @var string
	 */
	public $file_delim = '';

	/**
	 * RegEx for file include variable
	 *
	 * "/\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}/m";
	 *
	 * @access public
	 * @var string
	 */
	public $filevar_delim = '';

	/**
	 * RegEx for file includes with newlines
	 *
	 * "/^\s*\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}\s*\n/m";
	 *
	 * @access public
	 * @var string
	 */
	public $filevar_delim_nl = '';

	/**
	 * Template block start delimiter
	 *
	 * @access public
	 * @var string
	 */
	public $block_start_delim = '<!-- ';

	/**
	 * Template block end delimiter
	 *
	 * @access public
	 * @var string
	 */
	public $block_end_delim = '-->';

	/**
	 * Template block start word
	 *
	 * @access public
	 * @var string
	 */
	public $block_start_word = 'BEGIN:';

	/**
	 * Template block end word
	 *
	 * The last 3 properties and this make the delimiters look like:
	 * @example <!-- BEGIN: block_name -->
	 * if you use the default syntax.
	 *
	 * @access public
	 * @var string
	 */
	public $block_end_word = 'END:';

	/**
	 * Template tag start delimiter
	 *
	 * This makes the delimiters look like:
	 * @example {tagname}
	 * if you use the default syntax.
	 *
	 * @access public
	 * @var string
	 */
	public $tag_start_delim = '{';

	/**
	 * Template tag end delimiter
	 *
	 * This makes the delimiters look like:
	 * @example {tagname}
	 * if you use the default syntax.
	 *
	 * @access public
	 * @var string
	 */
	public $tag_end_delim = '}';
	/* this makes the delimiters look like: {tagname} if you use my syntax. */

	/**
	 * Regular expression element for comments within tags and blocks
	 *
	 * @example {tagname#My Comment}
	 * @example {tagname #My Comment}
	 * @example <!-- BEGIN: blockname#My Comment -->
	 * @example <!-- BEGIN: blockname #My Comment -->
	 *
	 * @access public
	 * @var string
	 */
	public $comment_preg = '( ?#.*?)?';

	/**
	 * Default main template block name
	 *
	 * @access public
	 * @var string
	 */
	public $mainblock = 'main';

	/**
	 * Script output type
	 *
	 * @access public
	 * @var string
	 */
	public $output_type = 'HTML';

	/**
	 * Debug mode
	 *
	 * @access public
	 * @var boolean
	 */
	public $debug = false;

	/**
	 * Null string for unassigned vars
	 *
	 * @access protected
	 * @var array
	 */
	protected $_null_string = array('' => '');

	/**
	 * Null string for unassigned blocks
	 *
	 * @access protected
	 * @var array
	 */
	protected $_null_block = array('' => '');

	/**
	 * Errors
	 *
	 * @access protected
	 * @var string
	 */
	protected $_error = '';

	/**
	 * Auto-reset sub blocks
	 *
	 * @access protected
	 * @var boolean
	 */
	protected $_autoreset = true;

	/**
	 * Set to FALSE to generate errors if a non-existant blocks is referenced
	 *
	 * @author NW
	 * @since 2002/10/17
	 * @access protected
	 * @var boolean
	 */
	protected $_ignore_missing_blocks = true;

Here is the function.

/**
* scans global variables and assigns to PHP array
*
* @access public
*/
public function scan_globals () {

	reset($GLOBALS);

	foreach ($GLOBALS as $k => $v) {
		$GLOB[$k] = $v;
	}

	/**
	 * Access global variables as:
	 * @example {PHP._SERVER.HTTP_HOST}
	 * in your template!
	 */
	$this->assign('PHP', $GLOB);
}

I noticed something. When I try to access the global variables in functions in the class it says they are not declared. Does this mean I have to declare my variables in each function in the class. It looks like to me it is this way.

Most of the functions pass the variables by reference except the function I put up here. If you need to see the whole XTemplate class let me know.

I tried to stuff the global variablesin an array in one of the function where it made the registered globals arrayand it did not work. What am I going to have to do here. It lookslike I might have to rewrite things having to do with the variables in the whole class. I need to use this classand write to retire registered globals. Tellme what you need to kow so I can get an answer.

Warning : Undefined property: XTemplate::$tag_start_delim in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 41

Warning : Undefined property: XTemplate::$tag_end_delim in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 41

Deprecated : Creation of dynamic property XTemplate::$filename is deprecated in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 85

Deprecated : Creation of dynamic property XTemplate::$tpldir is deprecated in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 89

Deprecated : Creation of dynamic property XTemplate::$mainblock is deprecated in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 98

Deprecated : Creation of dynamic property XTemplate::$tag_start_delim is deprecated in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 100

Deprecated : Creation of dynamic property XTemplate::$tag_end_delim is deprecated in /homepages/22/d4299051200/htdocs/admin/include/xtemplate.class.php on line 101

Here’s a function where it throws the error. I suppose I have change this into no registered globals.

public function __construct($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {

		$this->restart($file, $tpldir, $files, $mainblock, $autosetup, $this->tag_start_delim, $this->tag_end_delim);
	}

Do you really have to use this class? Why not switch something more modern, like Twig?

Slow down. What is the top-level problem you are trying to solve?

The purpose of scan_globals() method is so that you can use a tag like {PHP.some_var}, and the code will use the value of a variable - $some_var = ‘abc’;, instead of using ASSIGN() method calls to assign a value. If you are not using this type of tag, e.g. you are using {some_tag} and calling $xtpl->assign(‘some_tag’, ‘abc’);, this code has no effect.

I fixed the registered global problem. I just set up an array and kept the global variables utnot the global array.

The problem I am having now is that passing a null to preg match and str replaceis deprecated. There is a way to do it though. If anyone knows about this letme know.