<?php
class Header {
public static function displayHeader() {
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<?php
}
}
?>
Is that acceptable? Or should I use a Heredoc like this …
<?php
class Header {
public static function displayHeader() {
$header = <<<EOT
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
EOT;
echo $header;
}
}
?>
I like the former because the syntax highlighter of my editor works better with that. But wondering if it is bad practice, or whether it is common to do so.
In my opinion if you’re running into these types of issues than there isn’t enough separation between the display and application logic. You should consider using some type of template layer to force separation between the two.Unbox any well known MVC framework and rarely are there ANY hard-coded, embedded HTML strings anywhere besides in the display/template layer. The example Jeff Mott provided is a very basic example of the traditional pattern you should probably be using.