3 ms·
And now instead of $body = Http::request('GET', 'https://example.com')['body']; You have to do this? $body = Http::request(new Method('GET'), new URL
by TooCreative 6y ago
And now instead of
$body = Http::request('GET', 'https://example.com')['body'];
You have to do this?
$body = Http::request(new Method('GET'), new URL('https://example.com'))->body;
And you have cuttered the global namespace with "Method", "URL" and "Option"?
- tluyben2 6y agoWhy would they be in the global namespace? They would be in imported namespaces (something\Http for instance). That's rather normal. And yes, now you have to make sure you are passing the proper and valid types, which is obviously the goal here: $body = Http::request(Method.GET, URL.Parse('https://example.com'))->body; In other languages you can make it so that the static URL is validated at compile time even.
- TooCreative 6y agoFor that to work, you have to import those explicitly: use something\Http; use something\Http\Method; use something\Http\URL; $body = Http::request(Method.GET, URL.Parse('https://example.com'))->body; Now you have a bunch of lines instead of one. And have "Method" and "URL" in your current scope. And all of that instead of this beauty: $body = Http:request('GET', 'https://example.com')['body'];
- tluyben2 6y agoBeauty is in the eye of the beholder, however we were not talking about verboseness vs terseness though. You can make anything terse with stringy types and you indeed seem to favour that, however, this was about how types change readability and brittleness. This is all easier to read by people who do not know what request() does => request is not a good example, but it still stands. In your case, you have no case what $method or $url are supposed to be; you can do; $body = Http:request('rabbit', 'cracker')['body']; I assume something in Symfony catches that, but I cannot see it from the signature at all, and the validation error is, in my opinion (obviously) in the wrong place; it should be at the call site because that's where you are creating the erroneous input so that's where I want to be lead to.