M
M
mrWan2017-11-02 11:43:34
PHP
mrWan, 2017-11-02 11:43:34

Composer autoload fails to find the class. What could be wrong?

Connected two libraries phpQuery and CURL. Everything is ok with the first one, but CURL does not want to be loaded automatically.
Here is what I have in my code:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$pageText = new Curl();
$page = $pageText->get_page(URL);
$cat_page = phpQuery::newDocument($page);

throws an error: "Fatal error: Class 'Curl' not found in D:\domains\phpQuery\index.php on line 4";
I checked the vendor folder, all the libraries are there.
Here is my json just in case:
{
    "require": {
        "electrolinux/phpquery": "^0.9.6",
        "curl/curl": "^1.8"
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D3lphi, 2017-11-02
@mrWan

Don't forget that classes can have a namespace:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$pageText = new Curl\Curl();
$page = $pageText->get_page(URL);
$cat_page = phpQuery::newDocument($page);

Or:
<?php
require_once __DIR__ . '/vendor/autoload.php';

use Curl\Curl;

$pageText = new Curl();
$page = $pageText->get_page(URL);
$cat_page = phpQuery::newDocument($page);

E
Egor Petrov, 2017-11-02
@Hayate

Judging by the code namespace is not specified. See which one is used in the Curl library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question