I've programmed for many years now in c++/c/python but never did a project in PHP, which I will be doing soon.
1- I find the usage of echo to be somewhat annoying, especially for printing long stuff. For example, if I have a function which wants to echo a redundant part of a website, such as the header or a nav menu, what approach would be better.
<?php
function PrintHeader() {
[some php stuff, mysql queries, etc]
?>
some HTML code
more HTML code
<?php
[some closing php stuff]
}
?>
Is it better than
<?php
function PrintHeader() {
[some php stuff, mysql queries, etc]
echo 'some HTML code'
echo 'more HTML code'
[some closing php stuff]
}
?>
I find somewhat the first approach to be, to me, simpler, because you can modify the HTML code more easily without the echos. I tested it, it works, but is it a good approach? Is it valid?
2- Is it considered a good programming practice to use a function to echo a redundant part of a website, rather than copy/pasting the redundant code accross all PHP files?
These questions might sound obvious to some, but I have not much experience about code management in PHP. I always liked to reduce code redundancy as much as possible; it's easier to maintain.
<php?should be<?php- Plus, it's throwing off syntax highlighting, wouldn't you say Sam? - @JayBlanchardforeachvs%foreach%they'll have to learn the template language as well and their logic operators and functions. If the fronted guy can't pick-up a few common php or ruby functions I wouldn't hire them, they are simply not qualified for the job then - period. It's not 1998 any more and a template engine is just overhead.