Page 1 of 1

[solved] PHP 5.1.2: New ClassName == NULL

Posted: Sun May 14, 2006 4:26 pm
by santosj
Template.php

Code: Select all

<?php
require realpath(dirname(__FILE__).'/TemplateLite/class.template.php');

class Template
{
	private $template;
	function __constructor()
	{
		$this->template = new Template_Lite();
		
		if(is_object($this->template)) echo "Template is Object<br />\n";
		
		// Caching
		$this->template->cache = true;
		$this->template->cache_lifetime = 1800;
		$this->template->cache_dir = realpath(dirname(__FILE__).'/../template/cached');
		
		// Compiled
		$this->template->compile_dir = realpath(dirname(__FILE__).'/../template/compiled');
		$this->template->force_compile = false;
		
		// Template Folder
		$this->template->template_dir = realpath(dirname(__FILE__).'/../template');
	}
	
	function __call($function, $arguments)
	{
		$reflection = new ReflectionClass('Template_Lite');
		$method = $reflection->getMethod($function);
		
		/*
		 * Have to debug this. Works currently but haven't checked for methods that have more than zero
		 * parameters.
		 */
		return $method->invokeArgs($this->template, $arguments);
	}
}
?>
index.php

Code: Select all

<?php
require realpath(dirname(__FILE__).'/classes/core.template.php');

$template = new Template;

$templateLite = new Template_Lite;
?>
The class Template_Lite exists and the file is accessable.

Var dump of $template

Code: Select all

object(Template)#1 (1) {
  ["template:private"]=>
  NULL
}
Var Dump of $templateLite:

Code: Select all

NULL
I can't for the life of me figure out why it is that it won't work and I can only suspect that there is a bug in PHP 5.1.2, but I am most likely wrong. I do hope I'm wrong because it isn't so easy as to just 'fix' PHP as I would have to manually install it myself and I'm not up for that task. However, this worked on another domain, so I can't figure out why it wouldn't work now.

Case 1: I thought it might have to do with Template_Lite class being coded for PHP 4, but that wasn't right.

Case 2: Using the RelectionClass class, I was am to dump the contents of the class, so the case 1 was wrong was confirmed here.

Case 3: I did think for a second I had a lapse of insanity, but alas I was not so lucky.

Case 4: With all of my experience with New, I have never experienced such a result.

Case 5: First I extended the Template_Lite class and in the constructor tried to change the values, but the values would have update. Using Parent::variable = 'value' gave an error and using $this->variable would not update the parent values.

Posted: Sun May 14, 2006 9:01 pm
by Christopher
Are you sure that simply including the 'class.template.php' file and creating an object works?

Posted: Sun May 14, 2006 9:11 pm
by santosj
arborint wrote:Are you sure that simply including the 'class.template.php' file and creating an object works?
Yes. Is there any other way to create an object? Use the Reflection class allowed me to dump the correct contents of the Template_Lite class. However, $class = new Template_Lite; still did not work.

Posted: Sun May 14, 2006 9:16 pm
by Christopher
Actually the reflection above did not work either because Template::template is NULL.

Does something simple like the following work?

Code: Select all

require 'TemplateLite/class.template.php';
$template = new Template_Lite();
echo '<pre>' . print_r($template, 1) . '</pre>';

Posted: Mon May 15, 2006 8:45 am
by santosj
arborint wrote:Actually the reflection above did not work either because Template::template is NULL.

Does something simple like the following work?

Code: Select all

require 'TemplateLite/class.template.php';
$template = new Template_Lite();
echo '<pre>' . print_r($template, 1) . '</pre>';
Yes, that works, the in the Template class, the private template variable is still NULL and I can't access Template_Lite() from the index.php file. I should say that the relative path from index.php is 'classes/TemplateLite/class.template.php'.

The only issue now is that I can't get Template_Lite to work in the class that I have.

I am a Tool!

The issue was that I named the constructor to __constructor and it needed to be __construct().