Skip to content

Resolving env service before binding if class not found in configuration files. #39347

@oanhnn

Description

@oanhnn
  • Laravel Version: 8.67.0
  • PHP Version: 8.0.11

Description:

Resolving env service before binding if class not found in configuration files.

Steps To Reproduce:

In one config file (Eg. config/logging.php ), using a class, that isn't existed.

<?php

use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', ClassNotExisted::CONST_A),

Run: php artisan

Expected

Throw class ClassNotExisted not found exception

Actual

Throw ReflectionException and BindingResolutionException

Uncaught ReflectionException: Class "env" does not exist in project/vendor/laravel/framework/src/Illuminate/Container/Container.php:877
Next Illuminate\Contracts\Container\BindingResolutionException: Target class [env] does not exist. in project/vendor/laravel/framework/src/Illuminate/Container/Container.php:879

Reason

Try resolving env service before binding
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Log/LogManager.php#L523..L525

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions