With PHP's ob_start($callback), you can pass a static method as a callback like this:
class TemplateRenderer {
function myCallback($bufferContents) {
return 'Foobar instead of the buffer';
}
}
ob_start(array('TemplateRenderer', 'myCallback'));
Or you can refer to an object like this:
$myTemplateRenderer = new TemplateRenderer();
ob_start(array($myTemplateRenderer, 'myCallback'));
Both of these work, but I'd like to know if I can start the output buffer from within a class method, and refer to the callback using $this
class TemplateRenderer {
function myCallback($bufferContents) {
return 'Foobar instead of the buffer';
}
function init() {
// --- this doesn't work ----
ob_start(array($this, 'myCallback'));
// --- this doesn't work either ----
ob_start(array('this', 'myCallback'));
}
}
TemplateRenderer::init();
If it's even possible, what's the syntax for referring to a "callable" from within its own class?