My PHP experience is rather limited. I’ve just inherited some stuff that looks odd to me, and I’d like to know if this is a standard way to do things. The page which shows up in the browser location (e.g. http://www.example.com/example_page) has something like:
<?
$title = "Page Title";
$meta = "Some metadata";
require("pageheader.inc");
?>
<!-- Content -->
Then pageheader.inc has stuff like:
<?
@$title = ($title) ? $title : "";
@$meta = ($meta) ? $meta : "";
?>
<html>
<head>
<title><?=$title?></title
</head>
<!-- and so forth -->
Maybe others find this style useful, but it confuses me. I suppose this could be a step toward a rudimentary content management system, but the way it works here I’d think it adds to the processing the server has to do without reducing the load on the web developer enough to make it worth the effort.
So, is this a normal way to create pages with PHP? Or should I pull all this in favor of a better approach?
Also, I know that “<?” (vs. “<?php” ) is undesirable; I’m just reproducing what is in the code.
Well, it’s certainly not an invalid way to do it – but it might be a little cumbersome to read and maintain. I wouldn’t say there’s a “normal” way to do anything like this in PHP. At the end of the day, you’re outputting variables into HTML – so there aren’t a variety of options without using a dedicated templating engine (and/or heading towards a more MVC-based approach, as mentioned by ryeguy).
My suggestion: if it doesn’t suit your preferred style, change it. The most important thing, if you’re going to be developing and maintaining it, is that you can work with it comfortably, and efficiently.