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

Simple function names cause redeclare issues when using other code bases #20370

Closed
Artistan opened this issue Aug 1, 2017 · 2 comments
Closed

Comments

@Artistan
Copy link
Contributor

Artistan commented Aug 1, 2017

  • Laravel Version: 5.4.30
  • PHP Version: 7.1
  • Database Driver & Version: N/A

Description:

"Fatal error: Cannot redeclare" due to simple naming convention.
The

Steps To Reproduce:

try to use a code base (like adminer.php) with function declarations that are defined in helpers.php
Illuminate/Foundation/helpers.php Causes a fatal error

Example of one of the collisions in adminer.php
vrana/adminer#220 (comment)
Example of using adminer.php with laravel: https://github.com/leung0826/adminer-for-laravel
Example of forced fix to prevent collisions: https://github.com/leung0826/adminer-for-laravel/blob/master/src/Console/UpdateCommand.php#L120

Suggested Solutions future compatibility

  • don't use functions... use classes, namespaced?
  • deprecate the use of functions as helpers

Suggested Solutions 1 (class)

  • create a lf (laravel/framework) helpers class
  • implements each of the helper functions as static functions in the lf helper class

lf helpers class

  • lf::abort()
  • lf::abort_if()
  • lf::abort_unless()
  • lf::action()
  • lf::app()
  • lf::app_path()
  • lf::asset()
  • lf::auth()
  • lf::back()
  • lf::base_path()
  • lf::bcrypt()
  • lf::broadcast()
  • lf::cache()
  • lf::config()
  • lf::config_path()
  • lf::cookie()
  • lf::csrf_field()
  • lf::database_path()
  • lf::decrypt()
  • lf::dispatch()
  • lf::elixir()
  • lf::encrypt()
  • lf::event()
  • lf::factory()
  • lf::info()
  • lf::logger()
  • lf::method_field()
  • lf::mix()
  • lf::old()
  • lf::policy()
  • lf::path()
  • lf::public_path()
  • lf::redirect()
  • lf::request()
  • lf::resolve()
  • lf::resource_path()
  • lf::response()
  • lf::route()
  • lf::secure_asset()
  • lf::secure_url()
  • lf::session()
  • lf::storage_path()
  • lf::trans()
  • lf::trans_choice()
  • lf::__()
  • lf::url()
  • lf::validator()
  • lf::view()

Suggested Solutions 2 (namespace)

  • namespace the helpers functions lf
  • implements each of the helper functions as static functions in the lf helper class

lf helper functions in namespace

  • lf\abort()
  • lf\abort_if()
  • lf\abort_unless()
  • lf\action()
  • lf\app()
  • lf\app_path()
  • lf\asset()
  • lf\auth()
  • lf\back()
  • lf\base_path()
  • lf\bcrypt()
  • lf\broadcast()
  • lf\cache()
  • lf\config()
  • lf\config_path()
  • lf\cookie()
  • lf\csrf_field()
  • lf\database_path()
  • lf\decrypt()
  • lf\dispatch()
  • lf\elixir()
  • lf\encrypt()
  • lf\event()
  • lf\factory()
  • lf\info()
  • lf\logger()
  • lf\method_field()
  • lf\mix()
  • lf\old()
  • lf\policy()
  • lf\path()
  • lf\public_path()
  • lf\redirect()
  • lf\request()
  • lf\resolve()
  • lf\resource_path()
  • lf\response()
  • lf\route()
  • lf\secure_asset()
  • lf\secure_url()
  • lf\session()
  • lf\storage_path()
  • lf\trans()
  • lf\trans_choice()
  • lf\__()
  • lf\url()
  • lf\validator()
  • lf\view()
@themsaid
Copy link
Member

themsaid commented Aug 1, 2017

Yes these functions are reserved for Laravel.

I understand your point, but I don't think abandoning global namespace helpers is something Laravel would do since they're extremely helpful and widely used by developers.

Anyway, for suggestions and feature requests please use the https://github.com/laravel/internals repo.

@themsaid themsaid closed this as completed Aug 1, 2017
@kenorb
Copy link

kenorb commented Dec 11, 2017

Follow-up: laravel/ideas/issues/709

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