[php-src] Issue #18943: Arrow function vs require_once

From: Date: Wed, 25 Jun 2025 15:35:47 +0000
Subject: [php-src] Issue #18943: Arrow function vs require_once
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250323@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/18943 Author: zboszor ### Description The following code: retfunc.php ```php <?php return array('a', 'b'); ``` test-loadfile.php ```php <?php $path = 'retfunc.php'; $i = 1; $data = (fn () => require_once $path)(); while (is_array($data)) { $i++; $data = (fn () => require_once $path)(); if ($i > 100) break; } if (!is_array($data)) { echo 'not an array in round ' . $i . PHP_EOL; var_dump($data); } else echo 'success' . PHP_EOL; ``` Resulted in this output: ``` $ php test-loadfile.php not an array in round 2 bool(true) ``` But I expected this output instead: ``` $ php test-loadfile.php success ``` This is a minimal example that mimics Laravel's laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php that loads configuration files. Maybe it's an undocumented corner case, but require_once should return the file source the second and subsequent times without actually loading the file again, so the arrow function would produce the array value. The example code works if both arrow functions use `require˙. ### PHP Version ```plain PHP 8.4.8 (cli) (built: Jun 3 2025 16:29:26) (NTS gcc x86_64) Copyright (c) The PHP Group Built by Fedora Project Zend Engine v4.4.8, Copyright (c) Zend Technologies ``` ### Operating System Fedora 42

« previous php.bugs (#250323) next »