Override method called twice

I have a piece of code

<?php

abstract class Testing{
    public abstract function tester();

    public function testing(){
        $this->tester();
    }
}

class Test extends Testing{
    public function tester(){
        echo 'test';
    }
}

$t = new Test();
$t->testing();

I should have a way out test, but the conclusion that I get is - testtest?
Why tester()is it called twice?

Link to ideon

+4
source share
1 answer

PHP scripting language is case insensitive. (not relevant to variables though)

Since your class childhas no constructor, the constructor of the parent class starts.

When you do it.

$t = new Test();

Creates the constructor of the parent class, which is equal to public function testing()(see the name of the class match)

PHP.

, PHP 5 __construct() , , , .

+5

Source: https://habr.com/ru/post/1535727/


All Articles