PHP object-oriented method rewriting

WBOY
Release: 2016-07-30 13:29:43
Original
1524 people have browsed it

The wind is coming.fox

Because the sub-table is used, the method needs to be rewritten

Error report:

Declaration of ..... should be compatible with .....

Please use the following method to solve it

class  Model {
    /**设置分表名
     * @param  int $tableNum UID或表序号
     * @param int $num   位数
     * @return $this
     */
    public function tableSplit($tableNum=0,$num=2){
        $this->table($this->getTableNameSplit($tableNum,$num));
        return $this;
    }
}


class StockFlowModel extends Model {
    /**设置分表名
     * @param  int $tableNum UID或表序号
     * @param int $num
     * @return $this
     */
    public function tableSplit($tableNum=0,$num=4) {
        if(empty($tableNum)){
            $tableNum=date_time_format(DATE_TIME, 'ym');
        }
        parent::tableSplit($tableNum, $num);
        return $this;
    }
}
Copy after login

Note:

When overriding methods, the same conventions as the parent class methods, parameter names must be consistent, and attribute coverage must also be consistent.

When calling the parent class method, use the parent:: method to call

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the PHP object-oriented method rewriting, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template