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

Duplicate function name with Laravel #180

Open
borys-p opened this issue May 3, 2018 · 4 comments
Open

Duplicate function name with Laravel #180

borys-p opened this issue May 3, 2018 · 4 comments

Comments

@borys-p
Copy link

borys-p commented May 3, 2018

Hi,

It seems that both Gettext and Laravel are defining __() function. Although Laravel wraps their definition with function_exists(), it's not normally possible to register Gettext's functions before Laravel's helpers.php is loaded, as it's automatically included with Composer.

The only solution I've found so far (other than messing in vendor files) is https://github.com/funkjedi/composer-include-files.

@oscarotero
Copy link
Member

Thanks for the info.
Maybe @eusonlito (creator of the laravel-Gettext package) knows other workaround

@eusonlito
Copy link
Contributor

eusonlito commented May 3, 2018

I'm using the package with a require before vendor/autoload.php on public/index.php and artisan command.

# public/index.php
require __DIR__.'/../vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/../vendor/autoload.php';
# artisan
require __DIR__.'/vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/vendor/autoload.php';

Regards,
Lito.

@borys-p
Copy link
Author

borys-p commented May 10, 2018

Yes, that's another solution. But it's... inelegant. You make a strong coupling with a vendor library, while Laravel recently introduced auto-discovery feature to reduce this.

To be honest, the Composer hack isn't much better, but in theory Gettext could control it. If only there was a way to force Composer to include translator_functions.php before Laravel's helpers then it would fix this issue (I assume that if you include Gettext into Laravel, then you don't care about the built-in __() function).

@eusonlito
Copy link
Contributor

eusonlito commented May 10, 2018

Is not the best way to do it, but it's almost clear.

Laravel __ is loaded as helper function after check if not exists: https://github.com/laravel/framework/blob/4c9915c666c9cc085f5c749d640bcf0d309a64a5/src/Illuminate/Foundation/helpers.php#L926

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

3 participants