我有三个文件,即file1.php, file2.php and file3.php
在file1.php
中,我有一个变量var1。
file1.php:
<?php
$var1 = 'hello world';
?>
我需要file1.php in file2.php
并在file2.php
中有一个课程
file2.php:
<?php
require 'file1.php';
class demo{
function func1(){
echo $var1;
}
>?
在file3.php
中,我创建了一个演示类的对象,并调用了函数func1()。但是变量var1不可用。
file3.php
<?php
require 'file2.php';
$obj1 = new demo();
$obj1->func1();
所需的文件在类之外时是否不可用,但在同一文件中?是因为在调用函数file2.php中的require'file1.php'时未调用?为什么这样?有解决这个问题的好方法吗?
P.S。当我在file2.php的func1()函数中需要file1.php时,该变量可用
我有三个文件,分别是file1.php,file2.php和file3.php。在file1.php中,我有一个变量var1。 file1.php:我需要file2.php中的file1.php和...