Fatal error: Can not redeclare spl_autoload_register ()

0
<?php

function spl_autoload_register($class){require_once"{$class}.class.php";}

class ConDB
{
    private static $cnx;
    private function setConn()
    {
        return
        is_null(self::$cnx)?
            self::$cnx=new PDO("mysql:host=localhost;dbname=***","***","***"):
        self::$cnx;
    }
        public function getConn()
    {return $this->setConn();}
}
$cnx=new ConDB;
    
asked by anonymous 18.04.2018 / 15:59

1 answer

0

Because you are simply trying to create / redeem a function with the name of an existing native function :

function spl_autoload_register($class){require_once"{$class}.class.php";}

If the intention is to use spl_autoload_register , the correct would be to do this:

function meu_autoloader($class) {
    require_once"{$class}.class.php";
}

spl_autoload_register('meu_autoloader');

Or use closure (PHP anonymous function) directly:

spl_autoload_register(function ($class) {
    require_once"{$class}.class.php";
});
    
18.04.2018 / 16:34