Как я могу связать методы в PHP? [дубликат]Php

Кемеровские программисты php общаются здесь
Гость
Как я могу связать методы в PHP? [дубликат]

Сообщение Гость »


I'm looking to practice chaining methods in PHP.

I want to use the following code to return the

Код: Выделить всё

$_SERVER['REQUEST_METHOD']
value.

index.php

Код: Выделить всё

use App\Request; $request = new Request; echo $request->server->get('REQUEST_METHOD'); 
How would I write the Request class?

Request.php

Код: Выделить всё

namespace App; class Request {     public function server()     {         $key = $this->key;         return $_SERVER[$key];     }     public function get(string $key)     {         $this->key = $key;         return $this;     } } 
I am expecting to get the value GET. However, all I get is an error.


Источник: https://stackoverflow.com/questions/781 ... ods-in-php

Вернуться в «Php»