您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中静态方法如何继承

2025/11/30 1:21:12发布19次查看
php中静态方法继承的方法:使用override函数进行继承,代码为【function write(){echo 'i can be overriden!';}static function no_write()】。
php中静态方法继承的方法:
之前一直对子类能否对静态函数进行override,故写了段测试代码,代码如下:
<?phpclass a{var $a='i/'m a';function write(){echo 'i can be overriden!<br />';}static function no_write(){echo 'can i be overriden?<br />';} } class b extends a{function write(){echo 'override from a successfully!<br />';}static function no_write(){echo 'can i override successful?<br />';}}$a=new a;$a->write();$a->no_write(); $b=new b;echo $b->a.'<br />'; //attributes can be inherited$b->write();$b->no_write(); //static methods can be overriden?>
运行结果如下:
i can be overriden!can i be overriden?i'm aoverride from a successfully!can i override successful?
所以说,静态函数在子类里是可以被override的,但是在java里就不太清楚了,准备自己再写些代码测试下。a
相关免费学习推荐:php编程(视频)
以上就是php中静态方法如何继承的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product