tags:

views:

51

answers:

2

Hi There,

I was browsing the template.php file for the rootcandy theme and noticed some of the function names start with an underscore i.e.

function _rootcandy_admin_links()

function rootcandy_body_class()

Anyone know why this is? I thought the functions had to start with the name of the theme.

Many thanks

+2  A: 

Conventionally, underscores at the beginning of identifiers mean "This is private/internal stuff. You probably don't want to mess with it from other modules."

SamB
Thanks Sam. I didn't consider that you could just write your own functions in the template.php so it makes sense to underscore them with you theme name.
Nick Lowman
A: 

What SamB says, and also: functions in template.php only have to start with the theme name if they are meant to override an existing theme function. For example, when overriding theme_foo($variables), you use mytheme_foo($variables) in the template.php of the 'mytheme' theme. It's perfectly okay to add your own functions, like calculate_some_value() or _calculate_some_value(), if that helps you code your theme.

marcvangend
Generally due the lack of namespace in PHP, you don't create functions that doesn't contain the module or theme name to avoid naming colission. But this is a best practice not a requirement.
googletorp
-1 - **It is not 'perfectly ok'** to name your own functions as you wish! While it is correct that only overrides are *technically required* to start with the theme name, other functions should do this as well to *prevent naming clashes with other modules/themes* (the prefix convention is a kind of 'poor mans' solution to the lack of namespaces in PHP)
Henrik Opel
Please, if you quote, quote correctly. I'm not saying that it's okay to name as you wish. All I meant to say, is that it's okay to add your own functions besides theme override functions. I apologize if I didn't make myself clear enough. Proper namespacing is always good practice.
marcvangend
@marcvanged: Sorry for the imprecise quoting! I think I understood you alright - I just wanted to emphasize the point that the naming convention should be followed for non-override functions as well, even if not required.
Henrik Opel
Thanks for all your comments. Very helpful:)
Nick Lowman
@Henrik: ok, I understand, no hurt feelings.
marcvangend

related questions