Skip to content

[BUG] hyperf/watch Fatal error: Uncaught ErrorException: Trying to access array offset on false #7310

@ningkexin

Description

@ningkexin

Execute the command and paste the result below.

Command: uname -a && php -v && composer info | grep hyperf && php --ri swoole

Darwin MacBook-Pro.local 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 arm64
PHP 8.3.17 (cli) (built: Feb 11 2025 22:03:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.17, Copyright (c), by Zend Technologies
hyperf/cache                       3.1.43  A cache component for hyperf.
hyperf/code-parser                 3.1.52  A code parser component for Hyperf.
hyperf/codec                       3.1.42  A codec component for Hyperf.
hyperf/collection                  3.1.52  Hyperf Collection package which come from illuminate/collections
hyperf/command                     3.1.51  Command for hyperf
hyperf/conditionable               3.1.42  Hyperf Macroable package which come from illuminate/conditionable
hyperf/config                      3.1.42  An independent component that provides configuration container.
hyperf/config-center               3.1.42  The abstraction component of config center
hyperf/config-nacos                3.1.42  A nacos adapter for config center component.
hyperf/constants                   3.1.42  A constants component for hyperf.
hyperf/context                     3.1.42  A coroutine/application context library.
hyperf/contract                    3.1.42  The contracts of Hyperf.
hyperf/coordinator                 3.1.42  Hyperf Coordinator
hyperf/coroutine                   3.1.52  Hyperf Coroutine
hyperf/crontab                     3.1.42  A crontab component for Hyperf.
hyperf/database                    3.1.52  A flexible database library.
hyperf/db-connection               3.1.44  A hyperf db connection handler for hyperf/database.
hyperf/devtool                     3.1.51  A Devtool for Hyperf.
hyperf/di                          3.1.52  A DI for Hyperf.
hyperf/dispatcher                  3.1.42  A HTTP Server for Hyperf.
hyperf/engine                      2.13.1  Coroutine engine provided by swoole.
hyperf/engine-contract             1.12.0  Contract for Coroutine Engine
hyperf/event                       3.1.42  an event manager that implements PSR-14.
hyperf/exception-handler           3.1.42  Exception handler for hyperf
hyperf/filesystem                  3.1.42  flysystem integration for hyperf
hyperf/flysystem-oss               1.4.0
hyperf/framework                   3.1.42  A coroutine framework that focuses on hyperspeed and flexible, specifically use f...
hyperf/guzzle                      3.1.42  Swoole coroutine handler for guzzle
hyperf/http-message                3.1.48  microservice framework base on swoole
hyperf/http-server                 3.1.42  A HTTP Server for Hyperf.
hyperf/logger                      3.1.42  A logger component for hyperf.
hyperf/macroable                   3.1.42  Hyperf Macroable package which come from illuminate/macroable
hyperf/memory                      3.1.42  An independent component that use to operate and manage memory.
hyperf/model-listener              3.1.42  A model listener for Hyperf.
hyperf/nacos                       3.1.52  Nacos SDK
hyperf/pipeline                    3.1.42  Hyperf Macroable package which come from illuminate/pipeline
hyperf/pool                        3.1.42  An independent universal connection pool component.
hyperf/process                     3.1.48  A process component for hyperf.
hyperf/redis                       3.1.51  A redis component for hyperf.
hyperf/serializer                  3.1.42  A serializer component for Hyperf.
hyperf/server                      3.1.42  A base server library for Hyperf.
hyperf/stdlib                      3.1.42  A stdlib component for Hyperf.
hyperf/stringable                  3.1.50  Hyperf Stringable package which come from illuminate/support
hyperf/support                     3.1.51  A support component for Hyperf.
hyperf/tappable                    3.1.42  Hyperf Macroable package which come from illuminate/tappable
hyperf/testing                     3.1.52  Testing for hyperf
hyperf/translation                 3.1.42  An independent translation component, forked by illuminate/translation.
hyperf/utils                       3.1.42  A tools package that could help developer solved the problem quickly.
hyperf/watcher                     3.1.43  Hot reload watcher for Hyperf

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 6.0.1
Built => Feb 27 2025 15:25:06
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
openssl => OpenSSL 3.4.1 11 Feb 2025
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
curl-version => 8.12.1
zlib => 1.2.12
brotli => E16781312/D16781312
coroutine_sqlite => enabled

Directive => Local Value => Master Value
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 => 262144 => 262144

Description:

string(70) "/Users/xxx/www/xxx/app/Controller/xxx/XxxController.php"
string(27) "/Users/xxx/www/xxx"
array(3) {
  ["code"]=>
  int(0)
  ["signal"]=>
  int(0)
  ["output"]=>
  string(0) ""
}
Class reload success.
Stop server...
Stop server success.
Start server ...
string(70) "/Users/xxx/www/xxx/app/Controller/xxx/XxxController.php"
string(27) "/Users/xxx/www/xxx"
array(3) {
  ["code"]=>
  int(0)
  ["signal"]=>
  int(0)
  ["output"]=>
  string(0) ""
}
Class reload success.
Stop server...
Stop server success.
Start server ...
string(70) "/Users/xxx/www/xxx/app/Controller/xxx/XxxController.php"
string(27) "/Users/xxx/www/xxx"
bool(false)
PHP Fatal error:  Uncaught ErrorException: Trying to access array offset on false in /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php:81
Stack trace:
#0 /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php(81): Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler::Hyperf\ExceptionHandler\Listener\{closure}(2, 'Trying to acces...', '/Users/xxx/www...', 81)
#1 /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Command/WatchCommand.php(60): Hyperf\Watcher\Watcher->run()
#2 /Users/xxx/www/xxx/vendor/hyperf/command/src/Command.php(177): Hyperf\Watcher\Command\WatchCommand->handle()
#3 [internal function]: Hyperf\Command\Command->Hyperf\Command\{closure}()
#4 {main}
  thrown in /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php on line 81

Fatal error: Uncaught ErrorException: Trying to access array offset on false in /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php:81
Stack trace:
#0 /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php(81): Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler::Hyperf\ExceptionHandler\Listener\{closure}(2, 'Trying to acces...', '/Users/xxx/www...', 81)
#1 /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Command/WatchCommand.php(60): Hyperf\Watcher\Watcher->run()
#2 /Users/xxx/www/xxx/vendor/hyperf/command/src/Command.php(177): Hyperf\Watcher\Command\WatchCommand->handle()
#3 [internal function]: Hyperf\Command\Command->Hyperf\Command\{closure}()
#4 {main}
  thrown in /Users/xxx/www/xxx/vendor/hyperf/watcher/src/Watcher.php on line 81

Steps To Reproduce:

If you edit the same file multiple times, errors will occur.

exec

php bin/hyperf.php server:watch

watch config

use Hyperf\Watcher\Driver\FswatchDriver;
use Hyperf\Watcher\Driver\ScanFileDriver;

$isMac = (stripos(php_uname('s'), 'darwin') !== false) || (strtoupper(PHP_OS) === 'DARWIN');
return [
    'driver' => $isMac ? FswatchDriver::class : ScanFileDriver::class,
    'bin' => PHP_BINARY,
    'watch' => [
        'dir' => ['app', 'config'],
        'file' => ['.env'],
        'scan_interval' => 2000,
    ],
    'ext' => ['.php', '.env'],
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions