Home  >  Article  >  Backend Development  >  关于类继承函数重载的有关问题?大神进

关于类继承函数重载的有关问题?大神进

WBOY
WBOYOriginal
2016-06-13 10:52:09774browse

关于类继承函数重载的问题?大神进

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class a{function a(){...}function select(){...}}class b extends a{function b(){...}function select(){//这里能调用a类的select函数,但是我的感觉好像写法不规范,老感觉会死循环..$this->select();//是不是有别的写法//这写法 $a = new a(); $a->select();是不是比较耗内存,重新定义了一个对象)}}


------解决方案--------------------
只能这样写
parent::select();

$this->select();
这样写就是递归了
除非你确有需要,不然就锁死了
------解决方案--------------------
$this代表的本身,如果想调用你类的话,就用parent::,你这样写是重写了自己.
Statement:
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