1

From http://phphttpclient.com I followed "Install option 1" and the first "quick snippet".

I end up with the following, with Request undefined.

enter image description here

enter image description here

Additionally, and perhaps relatedly, I am confused by the fact that one of the code samples says "$response = Request::get" and another says "$response = \Httpful\Request::get". Is the latter valid PHP?

I have PHP 5.6.7.

enter image description here

What am I doing wrong?

cja
  • 10,504
  • 18
  • 66
  • 120
  • The docs have been updated to always include the namespace to avoid this confusion in the future, @cja. – nategood Sep 21 '15 at 18:18

2 Answers2

6

Yes, \Httpful\Request::get() is valid PHP. It tells PHP that you're looking for the class Request in the namespace Httpful. More on namespaces: http://php.net/manual/en/language.namespaces.php

The reason you can call \Httpful\Request::get(), but can't call Request::get() is namespace related. In your index.php, you're not defining a namespace. Therefor, PHP just looks for a class Request in the global space (when calling Request::get()). PHP does not check if there's a Request class in another namespace.

You can use (import) a class, that will prevent you from having to type the entire namespace everytime you want to use the Request class:

<?php

use Httpful\Request;
$request = Request::get()

# you can also rename the class if you have multiple Request classes
use Httpful\Request as Banana;
$request = Banana::get()

More on that subject: http://php.net/manual/en/language.namespaces.importing.php

Bjorn
  • 4,822
  • 1
  • 18
  • 34
1

I just followed the 'quick-hack' install suggested by the author and got the same result. I then used the fully qualified namespace and got it working.

as :

$response = \Httpful\Request::get($uri)->send(); // qualified namespace here

I'll stick to the hack while i kick the tires, then if i adopt the lib, i'll go the composer route (much much better imo).

YvesLeBorg
  • 8,943
  • 8
  • 33
  • 46