8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

composerで入れたパッケージがautoloadで見つからなくてエラーになっちゃう場合の対処法

Last updated at Posted at 2015-06-05

composerでHTTP_Request2を入れてみます

composer.json
{
    "require": {
        "pear/http_request2": "2.2.1"
    }
}
$ php composer.phar update

HTTP_Request2を使ってみます

test.php
<?php

require 'vendor/autoload.php';

$request = new HTTP_Request2();
print_r($request);
$ php test.php
php test.php 
PHP Warning:  require_once(Net/URL2.php): failed to open stream: No such file or directory in /Users/tsukui/Desktop/foo/vendor/pear/http_request2/HTTP/Request2.php on line 24
PHP Fatal error:  require_once(): Failed opening required 'Net/URL2.php' (include_path='/Users/tsukui/Desktop/foo/vendor/pear/pear_exception:.:/usr/lib/php/pear') in /Users/tsukui/Desktop/foo/vendor/pear/http_request2/HTTP/Request2.php on line 2

Net_URL2が入っているのに、includeできてないからエラーになっていますね

composer.jsonをこのようにします

composer.json
{
    "require": {
        "pear/http_request2": "2.2.1"
    },
    "include-path": [
        "vendor/pear/net_url2",
        "vendor/pear/http_request2"
    ]
}
$ php composer.phar update

再実行

$ php test.php 
HTTP_Request2 Object
(
    [observers:protected] => Array
        (
        )
中略
    [adapter:protected] => 
    [cookieJar:protected] => 
)

実行できるようになりました

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?