我在班里做了一个函数,就像那个
public function admin_ads_manage(){
$ads728=$_POST['ads728'];
$ads600=$_POST['ads600'];
$ads300=$_POST['ads300'];
$file728=stripslashes(file_get_contents($this->dir_name."/ads/ads728.txt"));
$file600=stripslashes(file_get_contents($this->dir_name."/ads/ads600.txt"));
$file300=stripslashes(file_get_contents($this->dir_name."/ads/ads300.txt"));
if($_POST['submit']){
$f728=fopen($this->dir_name."/ads/ads728.txt",'w');
$w728=fwrite($f728,$ads728);
$f600=fopen($this->dir_name."/ads/ads600.txt",'w');
$w600=fwrite($f600,$ads600);
$f300=fopen($this->dir_name."/ads/ads300.txt",'w');
$w300=fwrite($f300,$ads300);
echo "<meta http-equiv=\"refresh\" content=\"0\" " ;
}
我想在它之外的函数里面使用变量(仅)来打印索引页面中的输出,如何访问这个函数只允许使用一些var,而不是执行整个函数
我知道我可以通过$ object-&gt; function()执行整个功能; 但我只想使用一些var ..........
答案 0 :(得分:0)
private $myVar;
public function admin_ads_manage(){
$this->myVar = 'Your value';
// Rest of the code
}
public function getMyVar() {
return $this->myVar;
}
// Where you what to use it
echo $object->getMyVar();
答案 1 :(得分:0)
创建公共实例变量并访问它。
class A
{
public $var;
public function admin_ads_manage()
{
//skip some code
$this->var = "value to be accessed from outside";
}
}