Search code examples
phplaraveldrupaldrupal-7laravel-5

Function redeclaring error when using Drupal API in Laravel project


I've tried to bootstrap drupal API inside my laravel project by putting this code inside (public/index.php) file in laravel project directory :

 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
 define('DRUPAL_ROOT', $DOCUMENT_ROOT.'drupal738');
 require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

the bootstrap code is taken from drupal website :

https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_bootstrap/7

but when i open the login page on my laravel project the following error appears :

Fatal error: Cannot redeclare url() (previously declared in C:\wamp\www\laravelTest\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:566) in C:\wamp\www\drupal738\includes\common.inc on line 2333

and that's because there are some functions with the same names are both defined in laravel and drupal such url() and base_path() .

So is there any way to solve this without breaking any thing at laravel Or Drupal side ?


Solution

  • This is why global functions are bad practice. You can eventualy dig into drupal code and delete the function with same names like in laravel if they won't affect on the rest of code or you can refactor(rename) function in drupal codebase with some smart IDE.