1

I'm trying to use this library: https://github.com/duzun/hQuery.php

My project is ordonated like this:

BetCompare
  Application
    Teams
      file_using_the_library.php
      hQueryLib
        hquery.php

So here is how I'm using it in my php file:

namespace BetCompare\Application\Teams;
use BetCompare\Application\Teams\hQueryLib\hquery;

hQuery::$cache_path = "/path/to/cache";

This returns an error Class not found. I've tried this after a few researches on the matter:

namespace BetCompare\Application\Teams;
use BetCompare\Application\Teams\hQueryLib\hquery;
include_once 'hQueryLib/hquery.php';

hQuery::$cache_path = "/path/to/cache";

Then the error is the following: Cannot declare class hQuery_Context, because the name is already in use. I don't understand, the second error makes it look like the use was enough and loaded the class. But I can't use it... What am I doing wrong?

I've also tried only using include_once but it doesn't work.

1 Answer 1

4

Either like this (with namespace duzun\hQuery):

<?php

namespace BetCompare\Application\Teams;

use duzun\hQuery;

include_once 'hQueryLib/hquery.php';
hQuery::$cache_path = "/path/to/cache";

or like this, without the namespace:

<?php

namespace BetCompare\Application\Teams;

include_once 'hQueryLib/hquery.php';
\hQuery::$cache_path = "/path/to/cache";

Your code can not work, because if you write

use BetCompare\Application\Teams\hQueryLib\hQuery;

you are practically assuming, that the hQuery class has the namespace definition

namespace BetCompare\Application\Teams\hQueryLib;

which it does not have (beeing a third-party class).

The part with the duzun\hQuery is defined in the last lines of the hQuery.php file and described in the docus.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh I see, now it works! Thank you very much for the explanations.
You are welcome. Actually, If you read the additional text in the answer, you will discover that they provide a namespace for the class in a dynamical way, using class_alias(). Which is unfortunate, since you must have the docus beforehand, or know what those lines do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.