hyperf / hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
https://www.hyperf.io
MIT License
6.05k stars 1.18k forks source link

[BUG] PHP Fatal error: Cannot declare class, because the name is already in use #6908

Open Steinweber opened 5 days ago

Steinweber commented 5 days ago
Linux 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux
PHP 8.2.18 (cli) (built: Apr 11 2024 22:07:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.18, Copyright (c), by Zend Technologies
hyperf/cache                       v3.1.27 A cache component for hyperf.
hyperf/code-parser                 v3.1.27 A code parser component for Hyperf.
hyperf/codec                       v3.1.27 A codec component for Hyperf.
hyperf/collection                  v3.1.27 Hyperf Collection package which come from illuminate/collections
hyperf/command                     v3.1.27 Command for hyperf
hyperf/conditionable               v3.1.27 Hyperf Macroable package which come from illuminate/conditionable
hyperf/config                      v3.1.27 An independent component that provides configuration container.
hyperf/context                     v3.1.27 A coroutine/application context library.
hyperf/contract                    v3.1.27 The contracts of Hyperf.
hyperf/coordinator                 v3.1.27 Hyperf Coordinator
hyperf/coroutine                   v3.1.27 Hyperf Coroutine
hyperf/database                    v3.1.27 A flexible database library.
hyperf/db-connection               v3.1.27 A hyperf db connection handler for hyperf/database.
hyperf/devtool                     v3.1.27 A Devtool for Hyperf.
hyperf/di                          v3.1.27 A DI for Hyperf.
hyperf/dispatcher                  v3.1.27 A HTTP Server for Hyperf.
hyperf/engine                      v2.11.0 Coroutine engine provided by swoole.
hyperf/engine-contract             v1.10.1 Contract for Coroutine Engine
hyperf/event                       v3.1.27 an event manager that implements PSR-14.
hyperf/exception-handler           v3.1.27 Exception handler for hyperf
hyperf/framework                   v3.1.27 A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                      v3.1.27 Swoole coroutine handler for guzzle
hyperf/http-message                v3.1.27 microservice framework base on swoole
hyperf/http-server                 v3.1.27 A HTTP Server for Hyperf.
hyperf/logger                      v3.1.27 A logger component for hyperf.
hyperf/macroable                   v3.1.27 Hyperf Macroable package which come from illuminate/macroable
hyperf/memory                      v3.1.27 An independent component that use to operate and manage memory.
hyperf/model-listener              v3.1.27 A model listener for Hyperf.
hyperf/pipeline                    v3.1.27 Hyperf Macroable package which come from illuminate/pipeline
hyperf/pool                        v3.1.27 An independent universal connection pool component.
hyperf/process                     v3.1.27 A process component for hyperf.
hyperf/redis                       v3.1.27 A redis component for hyperf.
hyperf/serializer                  v3.1.27 A serializer component for Hyperf.
hyperf/server                      v3.1.27 A base server library for Hyperf.
hyperf/stdlib                      v3.1.27 A stdlib component for Hyperf.
hyperf/stringable                  v3.1.27 Hyperf Stringable package which come from illuminate/support
hyperf/support                     v3.1.27 A support component for Hyperf.
hyperf/tappable                    v3.1.27 Hyperf Macroable package which come from illuminate/tappable
hyperf/testing                     v3.1.27 Testing for hyperf
hyperf/translation                 v3.1.27 An independent translation component, forked by illuminate/translation.
hyperf/utils                       v3.1.27 A tools package that could help developer solved the problem quickly.
hyperf/validation                  v3.1.27 hyperf validation

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.1.1
Built => Apr  2 2024 09:03:56
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.11 19 Sep 2023
dtls => enabled
http2 => enabled
json => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

Description:

The ApartmentArea class is loaded as an Apartment class.

PHP Fatal error: Cannot declare class App\System\Lib\Api\Request\Apartment, because the name is already in use in /var/app/System/Lib/Api/Request/Apartment.php on line 7

The error only appears with exactly these two class names. If I rename ApartmentArea, everything works. Works:

Two classes like this also work

The folder App/System/Lib/Api/Request/ contains only these 2 classes for testing. The file name is also irrelevant. Foo.php contains ApartmentArea class and the problem occurs when starting the application.

The Runtime folder has also been emptied.

Steps To Reproduce:

App/System/Lib/Api/Request/Apartment.php

        declare(strict_types=1);
    namespace App\System\Lib\Api\Request;

    use App\System\Lib\Api\BaseRequest;

    abstract class Apartment extends BaseRequest{}

App/System/Lib/Api/Request/ApartmentArea.php

        declare(strict_types=1);
    namespace App\System\Lib\Api\Request;

    use App\System\Lib\Api\BaseRequest;

    abstract class ApartmentArea extends BaseRequest{}