DWilliams Posted August 5, 2010 Share Posted August 5, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/209859-does-including-or-requiring-a-file-execute-it-immediately/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 5, 2010 Share Posted August 5, 2010 include/require and the _once versions are php statements. The file being included/required is read and parsed/tokenized/interpreted at the time the include/require statement is executed. Quote Link to comment https://forums.phpfreaks.com/topic/209859-does-including-or-requiring-a-file-execute-it-immediately/#findComment-1095426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.