php4多级继承
这种继承对php4有效吗?
class A {
var $string;
function A () {
$this->string = "Hello";
}
}
class B extends A {
function B () {
$this->string = "World";
}
}
class C extends B {
function C () {
$this->string = "FooBar";
}
}
$a = new A();
$b = new B();
$c = new C();
// OUTPUT:
echo $a->string; // "Hello"
echo $b->string; // "World"
echo $c->string; // "FooBar"
Does this kind of inheritance work for php4?
class A {
var $string;
function A () {
$this->string = "Hello";
}
}
class B extends A {
function B () {
$this->string = "World";
}
}
class C extends B {
function C () {
$this->string = "FooBar";
}
}
$a = new A();
$b = new B();
$c = new C();
// OUTPUT:
echo $a->string; // "Hello"
echo $b->string; // "World"
echo $c->string; // "FooBar"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,当您进行交叉兼容性时,您应该创建一个在每个平台上按照最佳标准运行的交叉面包应用程序。
我这样做的方法是应用程序中需要 PHP 5 细节的部分,您将创建一个兼容目录并加载 PHP4 的兼容文件,
例如:
然后您可以这样做:
然后随着时间的推移,没有人使用 PHP 4您只需删除 compat 目录并删除
loadClass
中的检查即可。另一种方法是注册自动加载器,这样您就可以在应用程序中使用 require_once 进行编程,并减少在应用程序中放置额外函数的需要。
并具体回答您关于上述 hte 类的问题,这是完全交叉兼容的。
如果您坚持专门为 PHP4 创建应用程序,您应该考虑:
__construct
。&
符号通过引用传递。__tostring
或__destruct
等魔术方法。您应该始终在 PHP4 系统上创建应用程序,然后在最新版本的 PHP5 上进行测试。 (相应修改)
Firstly when your doing cross compatibility you should create a cross bread application that runs to the best standards on each platform.
The way I would do this is sections of the the application that require PHP 5 specifics you would create a compatible directory and load the compatible file for PHP4
for example:
is you can then do:
then as time goes on and nobody is using PHP 4 you can simply drop the compat directory and remove the check from
loadClass
.an alternative would be to register an autoloader, this way you can program using require_once within your application and reduce the need for an extra function to be palced through out your application.
and answer your questions specifically about hte class stated above, this is perfectly cross compatible.
If you stick with creating your application for PHP4 specifically you should take into consideration:
__construct
.&
symbol.__tostring
or__destruct
.You should always create you application on a PHP4 system, and then test on the latest version of PHP5. (amend accordingly)
查看PHP参考页面的注释,没有提到php4是否不支持多级继承。因此,它应该适用于版本 4。
也许,拥有 PHP 4 解释器的人可以保证。
Looking at the notes from PHP Reference pages, there isn't any mentioning whether multi-level inheritance wasn't supported in php4. Therefore, it should work with version 4.
Perhaps, someone having a PHP 4 interpreter can assure.