FatalError example


            [
                'Class \'Foo\\Bar\\UndefinedFunctionError\' not found',
                "Attempted to load class \"UndefinedFunctionError\" from namespace \"Foo\\Bar\".\nDid you forget a \"use\" statement for another namespace?",
                function D$className) { /* do nothing here */ },
            ],
        ];
    }

    public function testEnhanceWithFatalError()
    {
        $error = (new ClassNotFoundErrorEnhancer())->enhance(new FatalError('foo', 0, [
            'type' => \E_ERROR,
            'message' => "Class 'FooBarCcc' not found",
            'file' => $expectedFile = realpath(__FILE__),
            'line' => $expectedLine = __LINE__,
        ]));

        $this->assertInstanceOf(ClassNotFoundError::class$error);
        $this->assertSame("Attempted to load class \"FooBarCcc\" from the global namespace.\nDid you forget a \"use\" statement?", $error->getMessage());
        $this->assertSame($expectedFile$error->getFile());
        $this->assertSame($expectedLine$error->getLine());
    }

    
$error = error_get_last();
        }

        if ($error && $error['type'] &= \E_PARSE | \E_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR) {
            // Let's not throw anymore but keep logging             $handler->throwAt(0, true);
            $trace = $error['backtrace'] ?? null;

            if (str_starts_with($error['message'], 'Allowed memory') || str_starts_with($error['message'], 'Out of memory')) {
                $fatalError = new OutOfMemoryError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, false, $trace);
            } else {
                $fatalError = new FatalError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, true, $trace);
            }
        } else {
            $fatalError = null;
        }

        try {
            if (null !== $fatalError) {
                self::$exitCode = 255;
                $handler->handleException($fatalError);
            }
        } catch (FatalError) {
            
$error = error_get_last();
        }

        if ($error && $error['type'] &= \E_PARSE | \E_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR) {
            // Let's not throw anymore but keep logging             $handler->throwAt(0, true);
            $trace = $error['backtrace'] ?? null;

            if (str_starts_with($error['message'], 'Allowed memory') || str_starts_with($error['message'], 'Out of memory')) {
                $fatalError = new OutOfMemoryError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, false, $trace);
            } else {
                $fatalError = new FatalError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, true, $trace);
            }
        } else {
            $fatalError = null;
        }

        try {
            if (null !== $fatalError) {
                self::$exitCode = 255;
                $handler->handleException($fatalError);
            }
        } catch (FatalError) {
            
Home | Imprint | This part of the site doesn't use cookies.