A
A
Albert Kazan2018-08-29 13:07:03
PHP
Albert Kazan, 2018-08-29 13:07:03

Class methods are executed as static why?

I ran into an amazing problem. I have a class that has a couple of methods.
Example

class Response {
  public function execute() {
    return 'thing';
  }
}

in another place it was possible to call it like this
Response::execute()
. But Response->execute () does not work, it gives an error.
I create $r = new Response, the same troubles.
This is how they both work
echo Response::execute();
echo "\n";
# thing
$r = new Response;
echo $r->execute();
# thing

What the hell is this

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-08-29
@webinar

Turn on the output of all errors and you will see
As well as

$arr = [];
echo $arr['some'];

does not generate errors if disabled

A
Andrey, 2018-08-29
@VladimirAndreev

Response::execute() is a legacy of the past, don't do it this way.

$r = new Response;
echo $r->execute();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question