Large, multi-line variables but not large enough where you'd consider loading them externally. Would it be within the single use function as opposed to adding it to the class itself?
class MyClass{
var $tpl = 'ALOT OF TEXT HERE';
or within a class function
function MyFunction()
{
$tpl = 'ALOT OF TEXT HERE';
I'm all for better readability/maintainability by placing static variables at the top of classes, but not if it slows things down.
Depending on your particular use case it may be both, but for three reasons I would opt for function.
Firstly if you put it as a class variable, then it will be instantiated for every single instance (unless it is class side).
Secondly having it as a variable would imply that you want to change it. Since PHP doesn't have final
, you can't really tell those two apart. Since it is supposed to be a template, changing it for everyone may not be wanted.
Thirdly, having it a method helps with hiding the implementation. If you at later time decide to move it to separate file, database or wherever, then you can just change the behavior of the function returning it without affecting the clients.