0

i'm running an autoloader on my php application but it's returning a white screen with "Class 'FFI\Exception' not found" written in it.


<?php

spl_autoload_register(function ($class){
    $class_file = str_replace("\\", "/", $class) .".php";

    if(file_exists($class_file)) require_once $class_file;
});

?>


Class "FFI\Exception" not found


PHP 8.1.12 (cli) (built: Oct 25 2022 18:20:48) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies

In the beggining it was looking for a file "FFI\Exception.php". I added the file_exists as a solution, but now i'm here and i have no idea what to do.

  • You don't need an auto-loader for the `FFI\Exception` class, PHP either has or not has it. Very likely it is disabled, this is the extension: https://www.php.net/manual/en/class.ffi-exception.php - just enable the extension if you need the class. This boils down to a configuration issue of your PHP runtime environment. Also compare https://stackoverflow.com/q/57821515/367456 . – hakre Nov 20 '22 at 16:31
  • I've just changed "use FFI\Exception;" to "use Exception;" and now it is working properly. – Gianluca Starke Nov 20 '22 at 20:39
  • Well, define properly. You have a dependency that itself depends on FFI\Exception and it is/was not satisfied. When you redefine to depend on Exception then it will always work as Exception is always available, however it is not an FFI\Exception any longer. Additionally consider to use a more concrete exception than just Exception as it is very broad (exception base class in user-space). Double check your requirements. – hakre Nov 21 '22 at 00:09

0 Answers0