PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

.net - php如何实现C#那种类库的概念

原创
2016-06-06 20:20:56 786浏览

如下文件内容。

tool1.php

namespace MyTools;

class tool1
{

}

tool2.php

namespace MyTools;

class tool2
{

}

u.php

include MyTools\tool1;
include MyTools\tool2;

$t1 = new tool1();
$t2 = new tool2();

现在想实现的效果是,可以好像C#那样写,例如

include MyTools;

$t1 = new tool1();
$t2 = new tool2();

目的就是,如果命名空间一样的话,则只需要引用一次,就可以使用里面多个类,应该怎么写。。。?

回复内容:

如下文件内容。

tool1.php

namespace MyTools;

class tool1
{

}

tool2.php

namespace MyTools;

class tool2
{

}

u.php

include MyTools\tool1;
include MyTools\tool2;

$t1 = new tool1();
$t2 = new tool2();

现在想实现的效果是,可以好像C#那样写,例如

include MyTools;

$t1 = new tool1();
$t2 = new tool2();

目的就是,如果命名空间一样的话,则只需要引用一次,就可以使用里面多个类,应该怎么写。。。?

自动加载啊。。。

class
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。