how do i fix the error spl_autoload_register():Argument has been ignored

3.8k Views Asked by At

i get this error from my index page that is the only view page in the Model View Controller(MVC) project i have and with the code below in my index page

<?php 

define("ROOT", dirname(__DIR__) . DIRECTORY_SEPARATOR);
define("APP",ROOT . "app" . DIRECTORY_SEPARATOR);
define("VIEW", ROOT . "app". DIRECTORY_SEPARATOR . "view" . DIRECTORY_SEPARATOR);
define("MODEL",ROOT . "app" . DIRECTORY_SEPARATOR . "model" . DIRECTORY_SEPARATOR);
define("DATA", ROOT . "app" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR);
define("CORE" , ROOT . "app" . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR);
define("CONTROLLER", ROOT . "app" .DIRECTORY_SEPARATOR . "controller" . DIRECTORY_SEPARATOR);


$modules = [ROOT,APP,CORE,CONTROLLER,DATA];



$path = set_include_path(get_include_path() . PATH_SEPARATOR .implode(PATH_SEPARATOR,$modules));

spl_autoload_register("spl_autoload", false);
3

There are 3 best solutions below

0
thorne51 On

If you only want to use the default spl_autoload() implementation, I would suggest passing null as the first argument as per PHP documentation: https://www.php.net/manual/en/function.spl-autoload-register.php#refsect1-function.spl-autoload-register-parameters

0
noj On

As this comment on the PHP manual says:

Since PHP 8.0 spl_autoload_register() will always throw a TypeError on invalid arguments, therefore the second argument throw is ignored and a notice will be emitted if it is set to False.

So on PHP 8 you should no longer pass false as the 2nd argument.

0
CyberGirl On

just replace

spl_autoload_register("spl_autoload", false);

with

spl_autoload_register("spl_autoload");

Link to documentation

like this