require和require_once中的路径类似于(dir1 / dir2 / test.PHP).
我们可以创建相同的对象,如$obj = new class1 / class2;?
如果是,请解释.
http://php-fedex-api-wrapper.googlecode.com/svn/trunk/htdocs/example1.php
$rateRequest = new ComplexType\RateRequest();
解决方法:
它不使用路径,它使用的是namespace(ComplexType); PHP 5.3内置的功能.
更多信息:
> http://php.net/manual/en/language.namespaces.importing.php
但是,如果您要自动加载某些类,请查看__autoload
魔术函数.
Many developers writing
object-oriented applications create
one PHP source file per-class
deFinition. One of the biggest
annoyances is having to write a long
list of needed includes at the
beginning of each script (one for each
class).In PHP 5, this is no longer necessary.
You may define an __autoload function
which is automatically called in case
you are trying to use a
class/interface which hasn’t been
defined yet. By calling this function
the scripting engine is given a last
chance to load the class before PHP
fails with an error.
例:
function __autoload($class_name) {
include $class_name . '.PHP';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。