Jump to content

Does including (or requiring) a file execute it immediately?


DWilliams

Recommended Posts

Or is it all pieced together into one file then executed?

 

I ask because I'm thinking of a weird way to handle errors on my site that would integrate with the interface smoothly without much work on my part.

 

Every page on my site requires template_top.php at the start of the script and template_bottom.php at the bottom. I believe this is a pretty common thing to do, and it standardizes all my menus and interfaces and whatever else, plus it gives me a nice place to deliver messages to the user. What I want to do is something like this simplified example:

 

template_top.php:

<?php
// layout stuff here
try
{
?>

 

index.php:

<?php
require_once('template_top.php');
// a wild error appears!
throw new Exception('oh no!');
require_once('template_bottom.php');
?>

 

template_bottom.php:

<?php
}
catch (Exception $e)
{
   echo 'An error occured! Message: ' . $e->getMessage();
}
// layout stuff here
?>

 

So that's where my question comes in. Both template files contain code that, if executed on it's own, is invalid. Pieced together in my pages though, it forms correct code. I'd really like to do this since all I'd have to do if my script encounters a problem is throw an Exception and everything is instantly handled without me having to fight with display issues. If this isn't possible, does anybody have any better suggestions?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.