Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot redeclare class duzun\hQuery" right after install with composer #6

Closed
dragonattack opened this issue Apr 13, 2016 · 3 comments

Comments

@dragonattack
Copy link

I'm installing hQuery in laravel with composer:

dev@laravel:~/apps/testapp$ composer require duzun/hquery
Using version ^1.5 for duzun/hquery
./composer.json has been updated
Warning: You should avoid overwriting already defined auth settings for github.com.
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing duzun/hquery (1.5.0)
    Downloading: 100%

Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
dev@laravel:~/apps/testapp$ php artisan runcommand

  [ErrorException]
  Cannot redeclare class duzun\hQuery

runcommand contents:

use duzun\hQuery;
hQuery::$cache_path = '/home/dev/apps/testapp/storage/cache';

I've commented line //class_alias('hQuery', 'duzun\\hQuery'); in psr-4\hQuery.php and that solved the issue, but I'm not sure is that ok or not :)

@duzun
Copy link
Owner

duzun commented Apr 13, 2016

Thanks for taking time to report the issue @dragonattack !

You are not the first person to face this issue, but I never had the chance to test in Laravel (I guess it is v5, right?).

For the sake of PHP <= 5.2 I'm not using namespaces in main hquery.php file.
But I'm emulating them with psr-4 for guys that use PHP >= 5.3.

Basically it is enough to include hquery.php file in your project and start using hQuery class.

I guess Laravel also emulates psr-4 for the classmap key of composer.json and when it gets to /psr-4/hQuery.php, the duzun\\hQuery class has already been defined.

Could you try to replace the commented line with the following:

class_exists('duzun\\hQuery', false) or class_alias('hQuery', 'duzun\\hQuery');

@dragonattack
Copy link
Author

That fixes it! Thanks for your prompt response.
L5.2.29 PHP5.5.9

@duzun
Copy link
Owner

duzun commented Nov 16, 2016

Great! :-)

@duzun duzun closed this as completed Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants