Skip to content

Commit 134b0a9

Browse files
authored
Merge pull request #1712 from bertmsk/patch-1
Update Magic.php
2 parents eda2cd4 + fe0eb54 commit 134b0a9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Magic.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,17 @@ public static function start(bool $light): void
252252
self::$isIpcWorker = \defined('MADELINE_WORKER_TYPE') ? MADELINE_WORKER_TYPE === 'madeline-ipc' : false;
253253
// Important, obtain root relative to caller script
254254
$backtrace = debug_backtrace(0);
255-
self::$script_cwd = self::$cwd = \dirname(end($backtrace)['file']);
255+
256+
$last_entry = end($backtrace);
257+
$_cwd = '/tmp';
258+
if (array_key_exists('file', $last_entry))
259+
$_cwd = \dirname($last_entry['file']);
260+
else {
261+
if (preg_match('/^\{closure\:(.+?)\:/ui', $last_entry['function'], $m))
262+
$_cwd = \dirname($m[1]);
263+
}
264+
265+
self::$script_cwd = self::$cwd = $_cwd;
256266
if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') {
257267
try {
258268
error_reporting(E_ALL);

0 commit comments

Comments
 (0)