里面工作,我不知道为什么,但是这个代码为我工作一个月前......也许我升级了PHP,但记不起来了。用PHP 5.2.17和5.3.6Class对象不ob_start回调
为什么不能使用ob_start函数的回调内部类对象试过吗?
<?php
$f=new stdClass();
$f->title="awesome Title";
function callback($buffer)
{
global $f;
$buffer=str_replace("###TITLE###", $f->title, $buffer);
return $buffer;
}
ob_start("callback");
?>
This is the ###TITLE###
输出是:
PHP Notice: Trying to get property of non-object in /Users/qxxx/Sites/test/test.php on line 8
This is the
应该是:
This is the awesome Title
事实上,为了详细一点:这方面的一个重要组成部分,是_“未引用变量” _被破坏,引用的人都没有。一个很好的例子说明为什么'global'会使代码变得更难,并且适当地传递引用和参数是首选。 – Wrikken