类中不同文件的php范围变量
我无法访问变量create un一个特定文件并由另一个链接使用第三个链接。类中不同文件的php范围变量,php,scope,Php,Scope,我无法访问变量create un一个特定文件并由另一个链接使用第三个链接。 下面是一个示例,我有3个文件: testing.php <?php $special ="foo"; ?> other.php <?php echo $special; // that works class Testing { public function toto() { echo $special;//Error considering as undefined
下面是一个示例,我有3个文件:
testing.php
<?php
$special ="foo";
?>
other.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
?>
因此,如何在类测试的成员中访问变量
$special
。从函数中看不到$special变量。为此,在调用函数时,需要将$special变量作为参数传递给函数