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

WBOY
Release: 2016-06-06 20:20:56
Original
1145 people have browsed it

如下文件内容。

tool1.php

<code>namespace MyTools;

class tool1
{

}

</code>
Copy after login
Copy after login

tool2.php

<code>namespace MyTools;

class tool2
{

}

</code>
Copy after login
Copy after login

u.php

<code>include MyTools\tool1;
include MyTools\tool2;

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

</code>
Copy after login
Copy after login

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

<code>include MyTools;

$t1 = new tool1();
$t2 = new tool2();
</code>
Copy after login
Copy after login

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

回复内容:

如下文件内容。

tool1.php

<code>namespace MyTools;

class tool1
{

}

</code>
Copy after login
Copy after login

tool2.php

<code>namespace MyTools;

class tool2
{

}

</code>
Copy after login
Copy after login

u.php

<code>include MyTools\tool1;
include MyTools\tool2;

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

</code>
Copy after login
Copy after login

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

<code>include MyTools;

$t1 = new tool1();
$t2 = new tool2();
</code>
Copy after login
Copy after login

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

自动加载啊。。。

<code>class</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template