当前位置:Gxlcms > PHP教程 > .net-php如何实现C#那种类库的概念

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

时间:2021-07-01 10:21:17 帮助过:26人阅读

如下文件内容。

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

人气教程排行