我有一个函数,我想使用一个包含内,但我需要所有的变量是公共的类被干净地传递到页面布局包含文件。
变量在函数内部传递,而不是在传递给include时。有什么简单的建议吗?
private function printGraph() {
/*
if($_SERVER['HTTP_HOST']=='localhost') {
echo "<pre>n";
echo "Actual: ".$this->actual."n";
echo "Actual Bar: ".$this->actualbar."n";
echo "Attainable Bar: ".$this->attainablebar."n";
echo "Attainable: ".$this->attainable."n";
echo "ADSL2Calc: ".$this->adsl2calc."n";
echo "</pre>";
}
*/
//Adding the new look Tshooterlayout!
include 'tshooterlayout14.php';
// Actual Speed info and bar
$actual=file_get_contents("inc/troubleshooter/tshoot3-actual.inc");
$actual=sprintf($actual,$this->actual,$this->actualbar,$this->attainablebar);
直接使用$this:
test.php
<?php
class Test {
public $foo = 'bar';
public function testme(){
include "include.php";
}
}
$T = new Test();
$T->testme();
include.php
<?php
echo "You got your " . $this->foo ." in my foo!n";
结果$ php test.php
You got your bar in my foo!