The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I am making a PHP website, and I'm going to need lots of templates. So I researched on them, and I came to the conclusion that PHPLib's template system is the best option. I find this thing of having to set files before I can use them quite annoying, so I want to create a function to help. Here's my code so far for this:

Fatal error: Call to a member function on a non-object in /nusphere/apache/htdocs/org/global.php on line 16

I know I need to get the function to have access to the functions used in the template class, but I have tried adding a

PHP Code:

global $t;

line and I tried accessing the functions using

PHP Code:

$GLOBALS["$t"]->set_file(.........);

but none of them worked... Can anyone help?

Pleease... I have already wasted hours just with this problem...

Edit:

I'd like to add that it works if I access these functions outside the function, but I don't want that.

Thanks in advance.

Regards,

Pedro

<off-topic>I am running all this on two computers, on my own private server, all on one computer. http://www.vmware.com - I am hooked with it. Anyway, on the "real" computer I am running Windows 2000, and on the virtual machine, I am running RedHat 7.0 with NuSphere and networking enabled. It is just sooo cool. The possibilites are endless, and experiments can be done by backing up your entire computer, so it's great for trying out new stuff on, although it is quite slow. </off-topic>

Noooo!!! Still doesn't work. I also thought it would work but it still gives me the error message I quoted above. This is so unfair. Perhaps it is because of the PHP version I have (I think 4.0.4). Who knows. Any help would be appreciated, though.

I tell you what I think is a bit iffy about your code. You have a class Template, so naturally, the constructor name for this class is Template which you call when you instantiate the object $t*=*new*Template("templates");.

Now the thing is you have defined a function:function template*($template,$output="Main",$print=0)

Remember that in PHP function names are not case sensitive (which is crazy IMHO). Now you would expect that your function template should in no way conflict with the constructor for class Template as they are in completely different scope, global scope and class scope. However, I have always been a bit iffy about PHP's object orentedness, and suspect that this may be your problem. What happens if you change the name of your function from template to something else? Worth a try.

To say the truth, I had thought of that, but I never tried it. It was probably too late or something and my brain has SpeedStep on, so I don't think as well. Anyway, I'm now off to fix another syntax error on the same file... I hope this is a simple one.

Actually, I realised I had just created another syntax error when I renamed the function and all the references to it, but once I fixed it, the old error (the one that this thread is all about ) came back... Darn. Anyway, anyone have anymore ideas? Please...

OK - as well as renaming the function you included the line gobal $t; right?
Can you post your code on the internet as text and tell us the url? This doesn't make sense as Skunk said! Perhaps if we can see the entire code.

Also, one other thing would be to pass a reference to $t when you call the function so that the function signature would look something like:

function*template*($template, &$t, $output="Main",$print=0)

From a design perspective, what you appear to be doing is extending the functionalilty/behaviour of the class Template. So you could just add this function as a member function (with a different name) to class Template. For example if you call it function conditioinalParse():

Now from the perspective of a pure design, adding this function to the object would be achieved by using inheritence, so you would create a subclass of Template, such as MyTemplate. This is something I haven't looked into with PHP.