./与../的区别
下面我用实例来说明以上二者的区别:
如图一:
1:首先我将以下程序写进如上图根目录下test的index.php文件中。
class Foo{
private $var;
public function __construct(){
$this->var="HELLOWORLD";
}
public function test(){
return $this->var;
}
}
2:为了访问Foo类中的test()方法,下面我将实例化对象分别放在如上图中test2/test1.php和test.php文件中。其中test2/test1.php的代码如下:
include '../test/index.php';
$F=new Foo();
echo $F->test();
输出结果为:
>HELLOWORLD
test.php中代码如下:
include './test/index.php';
$F=new Foo();
echo $F->test();
输出结果为:
>HELLOWORLD
如果是多层文件夹下,则要使用:
例子: include "../../hello1/hello.php";
注:通过以上实例,即可验证./与../的区别;