Jump to content

Obliviate missing endpage()'s


Recommended Posts

I have to admit it's been some time since I laid my hands on an MCCodes script, so best practices out the window.

I would like to give MCCodes developers a useful tip.

How many times haven't you missed a $h->endpage(); initialization? I know I have had my fair share of times.

When it comes to output buffering for template systems, it's really a nuisance to work with.

So, I've come up with a hack for it...

MCCodes uses a class named headers for all it's templating needs, and using a bit of OOP knowledge one can automatically "close" a script that doesn't have the endpage() initialization present.

It's called a destructor. It executes automatically every time the class is destroyed, or in human terms, when the script has finished executing.

One can simply place the endpage() initialization in there, with a logical statement, so that you never get caught of guard by it again.

So here's a little bit of code that could make your life easier... It works on all versions of MCCodes, to my knowledge that is.


class headers {

  // simple $h->endpage missing fix 
  private $page_closed = false;

  function __destruct() {
     if (empty($this->page_closed)) 

     return true;

// the rest of the script

  function endpage() {
     global $db,$c,$userid, $set,$ir;

     $this->page_closed = true;

     // rest of code
} // end of headers{}


It might be useful to some, and not to others.

But I just thought I would share this age old hack.


Edited by Spudinski
I = Fool.
  • Like 1
Link to comment
Share on other sites

Eh, I think you made a typo in the method name (__destruct?)... Otherwise, good stuff. The original code was not written with PHP 5 in mind, though, hence why something like this isn't already there.

Thanks for mentioning that silly mistake of mine.

Even if it was written with PHP5 in mind, I get why something like this is not implemented.

My best guess would be conforming to a specific coding style.

But, please be aware that this is not to discredit MCCodes, it's the other way around actually.

This is just a simple hack I mostly use on development environments, it's a short-cut method of doing things that isn't possible with the current MCCodes architecture.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...