php类中Differents文件的作用域变量


php Scope Variable from Differents files in class

我无法访问变量create un一个特定文件,并由第三个链接的另一个链接使用
下面是一个例子,我有3个文件:
testing.php

<?php 
$special ="foo";
?>

其他.php

<?php
echo $special; // that works
class Testing
{
   public function toto()
   {
     echo $special;//Error considering as undefined
   }
}
?>

main.php

<?php
require 'testing.php';
echo "require work $special";// that works
require 'other.php';
$a = new Testing();
$a->toto();//error
?>

那么,我如何在Testing类的成员中访问我的变量$special呢。

$特殊变量在函数中不可见。要实现这一点,您需要在调用函数时将$special变量作为参数传递给它。