数码资讯
在PHP5虚拟功能共享
请看下面的代码: 复制代码代码如下所示: < PHP 类{ 公共函数x(){ 被调用。; } 公共函数y(){ 自我::x(); 调用a::y()。; } 公共函数Z(){ $ $ x(x); 调用a:Z()。; } } B类扩展{ 公共函数x(){ 被调用。; } } 新的b(); $ B = y
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
请看下面的代码:
复制代码代码如下所示:
< PHP
类{
公共函数x(){
被调用。;
}
公共函数y(){
自我::x();
调用a::y()。;
}
公共函数Z(){
$ $ x(x);
调用a:Z()。;
}
}
B类扩展{
公共函数x(){
被调用。;
}
}
新的b();
$ B = y();
;
$ - Z();
>
在这种情况下,a::(y)调用a::(x),并且:(x::x())用一个:(x)表示,然后调用B::y(),B::(y)应该调用或失败()In C++, if A:: X () is not defined as a virtual function, then B:: Y () (that is A:: Y ()) will invoke A:: X (), and if A:: X (), use x keyword to be defined as a virtual function, then: : () will call :.In PHP5, however, the function of the virtual function is implemented by the self and $this keywords.If the parent class: Y (A:): X (self:) used in the way of calling A:: X (), so in the sub class of A: (x): no matter whether covered, A:: Y () call is A:: X (); and if the parent class A:: Y ($this->x) () calls the A:: X (), so if the subclass of A:: X (B:) is: X () A: (y): coverage, will call the B: (x).
以上结果如下:
答:X()被称为。答:被称为y()。——
B::X()被称为。答:被称为Z()。
virtual-function.php
复制代码代码如下所示:
< PHP
类parentclass {
静态公共函数说($ STR){
静态::do_print($str);
}
静态公共功能do_print($str){
父;
}
}
子类扩展parentclass {
静态公共功能do_print($str){
孩子说:;
}
}
类anotherchildclass延伸parentclass {
静态公共功能do_print($str){
回声anotherchild说$str ;
}
}
phpversion(回声);
美元=新ChildClass();
$(你好)->说;
$ =新AnotherChildClass();
$ B ->说(你好);
复制代码代码如下所示:
< PHP
类{
公共函数x(){
被调用。;
}
公共函数y(){
自我::x();
调用a::y()。;
}
公共函数Z(){
$ $ x(x);
调用a:Z()。;
}
}
B类扩展{
公共函数x(){
被调用。;
}
}
新的b();
$ B = y();
;
$ - Z();
>
在这种情况下,a::(y)调用a::(x),并且:(x::x())用一个:(x)表示,然后调用B::y(),B::(y)应该调用或失败()In C++, if A:: X () is not defined as a virtual function, then B:: Y () (that is A:: Y ()) will invoke A:: X (), and if A:: X (), use x keyword to be defined as a virtual function, then: : () will call :.In PHP5, however, the function of the virtual function is implemented by the self and $this keywords.If the parent class: Y (A:): X (self:) used in the way of calling A:: X (), so in the sub class of A: (x): no matter whether covered, A:: Y () call is A:: X (); and if the parent class A:: Y ($this->x) () calls the A:: X (), so if the subclass of A:: X (B:) is: X () A: (y): coverage, will call the B: (x).
以上结果如下:
答:X()被称为。答:被称为y()。——
B::X()被称为。答:被称为Z()。
virtual-function.php
复制代码代码如下所示:
< PHP
类parentclass {
静态公共函数说($ STR){
静态::do_print($str);
}
静态公共功能do_print($str){
父;
}
}
子类扩展parentclass {
静态公共功能do_print($str){
孩子说:;
}
}
类anotherchildclass延伸parentclass {
静态公共功能do_print($str){
回声anotherchild说$str ;
}
}
phpversion(回声);
美元=新ChildClass();
$(你好)->说;
$ =新AnotherChildClass();
$ B ->说(你好);
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。