E
E
Egor Gruzdev2017-02-06 18:23:46
PHP
Egor Gruzdev, 2017-02-06 18:23:46

Is it correct to use the following calls?

error_reporting(E_ALL);


class Test {

    public function t2()
    {
        $this->t();
    }

    public static function t()
    {
        echo 1;
    }
}

$test = new Test();

$test->t2();
$test->t();
Test::t();

There are no errors, only "autocomplete" in Phpstorm does not work when you try to access the "t" method through "->"
PS
in the t() method there will never be an object call, but sometimes you need to call this method as a class method without creating an object .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2017-02-06
@egor_gruzdev

don't do that
$test->t();
read about static methods

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question