I have a global “functions.php” file containing functions used throughout my site.
In terms of performance, efficiency, etc – is it better to call one of these functions directly or to define them as constants and call the constant instead? (Or does it matter at all?)
ie
<?php echo site_root(); ?>
vs.
<?php echo SITEROOT; ?>
Thanks
It depends on what
site_root()does exactly.If all it does is something very simple like read from an array and return a string, it doesn’t matter whether you use the function, or a constant. Use whatever works best for you.
If the function does something expensive like a database lookup, it is indeed wise to do the call only once, store the result in a constant, and use that in the code.