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

[11.x] Fixes function loading conflicts when using @include('vendor/autoload.php') via Laravel Envoy #52974

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

s-damian
Copy link
Contributor

With Laravel envoy we have this error:

user@linux:/path/laravel-project$ envoy run local_to_preprod
PHP Fatal error:  Cannot redeclare Illuminate\Support\defer() (previously declared in /home/steph_d/.config/composer/vendor/illuminate/support/functions.php:17) in /media/steph_d/data_sd/www/apps/perso/laravel-cms/vendor/laravel/framework/src/Illuminate/Support/functions.php on line 26
PHP Stack trace:

We need to add function_exists to avoid these errors.

Thanks.

@s-damian s-damian changed the title Fix conflicts with ading function_exists in Support functions Fix conflict between Laravel Envoy and Illuminate/Support/functions.php Sep 29, 2024
Copy link
Contributor

@rojtjo rojtjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow missed the functions are namespaced. This needs to be included in the function_exists check.

src/Illuminate/Support/functions.php Outdated Show resolved Hide resolved
src/Illuminate/Support/functions.php Outdated Show resolved Hide resolved
@s-damian
Copy link
Contributor Author

The tests are finally passed

@crynobone
Copy link
Member

@s-damian Can you provide a reproducing step for this? I tested with having illuminate/support available via Composer Global and Laravel app and doesn't have this issue. Furthermore, there are namespaced functions within other components.

@s-damian
Copy link
Contributor Author

s-damian commented Sep 30, 2024

Install Composer :

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Install Laravel Envoy :

cd ~
composer global require laravel/envoy
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc

Use Laravel Envoy :

cd /path-to-your-laravel-project
envoy run deploy_to_remote_server

envoy run deploy_to_remote_server return PHP Fatal error "Cannot redeclare Illuminate\Support\defer()..."

@crynobone
Copy link
Member

CleanShot 2024-09-30 at 18 15 42

Still unable to replicate the issue. Which version of Composer are you using (Run composer diagnose and share the output)?

@s-damian
Copy link
Contributor Author

s-damian commented Sep 30, 2024

The latest version

user@linux:/laravel-path$ php artisan --version
Laravel Framework 11.25.0

user@linux:/laravel-path$ composer --version
Composer version 2.7.9 2024-09-04 14:43:28
PHP version 8.3.12 (/usr/bin/php8.3)
Run the "diagnose" command to get more detailed diagnostics output.

user@linux:/laravel-path$ composer about
Composer - Dependency Manager for PHP - version 2.7.9
Composer is a dependency manager tracking local dependencies of your projects and libraries.
See https://getcomposer.org/ for more information.

And: Laravel Envoy 2.9.0

@crynobone
Copy link
Member

CleanShot 2024-09-30 at 19 28 40

Still unable to replicate the issue.

@servers(['localhost' => '127.0.0.1'])

@task('inspire')
    php artisan inspire
    echo 'Run `inspire` command'
@endtask
<?php

use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;

use function Illuminate\Support\defer;

Artisan::command('inspire', function () {
    defer(fn () => ray(Inspiring::quote()));

    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote')->hourly();

@rojtjo
Copy link
Contributor

rojtjo commented Sep 30, 2024

I believe this is caused by requiring the app's autoloader as described in https://laravel.com/docs/11.x/envoy#setup

@servers(['localhost' => '127.0.0.1'])

@include('vendor/autoload.php')

@task('inspire')
    php artisan inspire
    echo 'Run `inspire` command'
@endtask

@s-damian
Copy link
Contributor Author

I have already this:

@include('vendor/autoload.php')

@s-damian
Copy link
Contributor Author

s-damian commented Sep 30, 2024

With @include('vendor/autoload.php'):

@servers(['localhost' => '127.0.0.1'])

@include('vendor/autoload.php')

@task('inspire')
    php artisan inspire
    echo 'Run `inspire` command'
@endtask

we have fatal error

@s-damian s-damian closed this Sep 30, 2024
@s-damian
Copy link
Contributor Author

And without With @include('vendor/autoload.php'):, I have others errors:

PHP Fatal error: Uncaught Error: Class "Dotenv\Dotenv"
Because I use this:

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

@crynobone crynobone reopened this Sep 30, 2024
@crynobone crynobone changed the title Fix conflict between Laravel Envoy and Illuminate/Support/functions.php [11.x] Fixes function loading conflicts when using @include('vendor/autoload.php') via Laravel Envoy Sep 30, 2024
@taylorotwell taylorotwell merged commit 39a60f1 into laravel:11.x Sep 30, 2024
61 checks passed
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

Successfully merging this pull request may close these issues.

4 participants