Currently, I'm printing some html by including functions.
Should I create a class for printing html? Thereby, making the functions static.
Like that I can remember where these functions are from.
Because not all my pages using all the functions. Some pages only use one function.
Using static functions is the right move here?
Should I use static functions for printing html
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Currently, I'm using this
Thinking of changing it to this instead:
Code: Select all
function printLink($name, $address){
echo '<a href="' . $address . '">' . $name . '</a>';
}Code: Select all
class HTMLPrinter{
static public function printLink($name, $address){
echo '<a href="' . $address . '">' . $name . '</a>';
}
}We get one benefit by making methods static.we can call static methods without creating an object of the class.Because not all my pages using all the functions. Some pages only use one function.
Using static functions is the right move here?
Code: Select all
HTMLPrinter::printLink($name, $address);- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US