0

We've all seen websites with code like this:

<!-- begin /a4/includes/nav_include.php -->
  <div ... >
<!-- end /a4/includes/nav_include.php -->

This is sloppy and annoying, but I understand the need to be able to figure out what file is responsible for the source code you're seeing. What I'd prefer is a way to make all included and required files automatically spit this info out, but only when in a toggleable dev mode.

Obviously, I could do something like this:

<?php
  if($devmode){ echo "<!-- begin /a4/include/snav_include.php -->"; }  
  include("/a4/includesnav_include.php");
  if($devmode){ echo "<!-- end /a4/includes/nav_include.php -->"; }  
?>

But that just becomes annoying and sloppy on a whole other level. I'd prefer to get the best of both worlds, where I have the functionality of above but can still write my includes like this:

<?php include("/a4/includes/nav_include.php"); ?>

Is there a way to do this?

brentonstrine
  • 21,694
  • 25
  • 74
  • 120
  • When you realize that all the output must be done in one place only - this technique becomes pointless. So: you only need that if you do perform output in multiple places. – zerkms Oct 30 '14 at 23:34
  • What does it mean to perform output? – brentonstrine Oct 30 '14 at 23:36
  • Running `echo`, `print`, or any other function that produces output. – zerkms Oct 30 '14 at 23:37
  • 1
    This is one of the primary reasons to go (H)MVC. – Ohgodwhy Oct 30 '14 at 23:37
  • Ah. Well maybe once I get everyone here to stop creating table based layouts we can work on that. – brentonstrine Oct 30 '14 at 23:38
  • HTML details have nothing to do with it actually. Your HTML may be as terrible as hell, but with nice php that produces it. – zerkms Oct 30 '14 at 23:39
  • The point is that I'm working with people of various skill levels and there are a lot of very old habits that are not going to be easy to get them to break. Completely changing the way PHP is used is not going to happen here until all the old dogs retire. – brentonstrine Oct 30 '14 at 23:43
  • 1
    Wrap those 3 lines in a function then – zerkms Oct 30 '14 at 23:45
  • 1
    Are you wanting to [redefine `include()`](http://stackoverflow.com/questions/2326835/redefine-built-in-php-functions)? – Jared Farrish Oct 30 '14 at 23:52

0 Answers0