cja*_*cja 1 php phar phpstorm httpful
从http://phphttpclient.com我按照"安装选项1"和第一个"快速片段".
我最终得到以下内容,请求未定义.


另外,也许是相关的,我对其中一个代码示例说"$ response = Request :: get"而另一个代表"$ response =\Httpful\Request :: get"这一事实感到困惑.后者是有效的PHP吗?
我有PHP 5.6.7.

我究竟做错了什么?
是的,\Httpful\Request::get()是有效的PHP.它告诉PHP你正在寻找Request命名空间中的类Httpful.有关命名空间的更多信息:http://php.net/manual/en/language.namespaces.php
你可以调用\Httpful\Request::get(),但不能调用的原因Request::get()是命名空间相关.在你的index.php,你没有定义命名空间.因此,PHP只Request在全局空间中查找一个类(调用时Request::get()).PHP不会检查Request另一个命名空间中是否有类.
您可以use(导入)一个类,这将阻止您每次要使用Request该类时都必须键入整个命名空间:
<?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()
Run Code Online (Sandbox Code Playgroud)
有关该主题的更多信息:http://php.net/manual/en/language.namespaces.importing.php