我是仿照了一个叫做phpSay的微博源代码来做这个实验的,这个项目源码包含个仿smarty的模板引擎。我写了三个文件。test.php:<?php
require_once("scopeTest.php");echo "This is main page.\n<br>";$t = scopeTest(5);//echo $t->m_temp;$t->test();//var_dump($t);
?>
scopeTest.php:<?php
class scopeTest
{
var $m_temp = 0; function scopeTest($num = 0)
{
echo "the object is constructing.";
$this->m_temp = $num;
}
function test()
{
$varInFun = "I am a var within member function scope of scopeTest";
include("include/included.php");
}
}
?>include/included.php:<html>
<head></head>
<body>
<?php
echo '$varInFun defined in the function: <br>';
echo "\n";
echo $varInFun;
?>
</body>
</html>
测试结果就是该脚本只会输出:This is main page.
<br>我查阅了PHP.NET上面关于include的手册(http://php.net/manual/en/function.include.php),我觉得我这样写也是正确的,可是结果与预料的不同。这里有个文件结构的截图:
请各位帮忙解惑~~~谢谢。