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

Conflict with env function #1647

Open
oscarotero opened this issue Dec 2, 2019 · 10 comments
Open

Conflict with env function #1647

oscarotero opened this issue Dec 2, 2019 · 10 comments
Labels

Comments

@oscarotero
Copy link

Hi.
My site stopped working because I have a env function to return environment variables and I just realized this library use CakePHP, that defines another env function before, so the site was using the cake's function that have a different behaviour.
Is there any way to have phinx installed without having these functions defined by default? (Maybe using a phar file or something like that).

Thanks!

@markstory
Copy link
Member

Is there any way to have phinx installed without having these functions defined by default? (Maybe using a phar file or something like that).

We don't currently create phar files. I'm not too familiar with the tooling to do so either, perhaps another contributor is.

@dereuromark
Copy link
Member

The same trick might also work here: #1401 (comment)

@oscarotero
Copy link
Author

The same trick might also work here: #1401 (comment)

Yes and no

I'm using oscarotero/env library to get environment variables and it provides a env() function (https://github.com/oscarotero/env#the-env-function)

The library does not expose that function by default (it is not autoloaded by composer), you have to run Env::init() so it's not posible to execute this funcion before include composer autoload php file.

The only workaround is to don't use the env function (but Env::get() instead). Other option is include manually the function before include composer (https://github.com/oscarotero/env/blob/master/src/env_function.php).

Anyway, I've started to using this library before it was converted to a cake component and would like it to remain a standalone framework-agnostic tool, so IMO, polluting the global with these functions is not a good idea. Global functions should be defined/loaded and used by final users, but not by dependencies. Maybe cake could expose its funcions under its own namespace, or using a class with static methods.

@dereuromark
Copy link
Member

@markstory Any way we can do this?

@markstory
Copy link
Member

The env() function in Cake is conditionally defined. If your application defines the function first the Cake one won't be created.

Not autoloading the env() function entirely could be possible, but runs a high risk of breaking compatibility unless we can come up with a way to ensure env() exists everywhere but in phinx's usage.

@dereuromark
Copy link
Member

We should add a docs example how to load custom one before the core.
That would solve it for n ow.

@rquadling
Copy link
Collaborator

A library that has some helper functions but pollutes the global namespace is really not very nice. Move the global methods to the Cake specific namespace, and heavily document a polyfiller project that reinstates the global pollution with a strong suggestion that the consumer's code should be upgraded to use the Cake specific namespace if they want to continue using the global function.

I'm unsure if we should be using a static class, as there is a small semantic difference between a static method and a namespaced class (so small I can hardly see it).

This is one of my biggest gripes with another well known and popular framework that starts with L.

In short why does ANY framework think it should be able to pollute the global namespace.

@lorenzo
Copy link
Member

lorenzo commented Mar 10, 2020

I just with PHP had function autoloading

@rquadling
Copy link
Collaborator

@pooriamo
Copy link

pooriamo commented May 23, 2021

I use psysh REPL library which includes autoload.php in runtime. So I can't define my own env function before that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants