Autoload function on PHP. Code example open

Autoload function on PHP. Code example

When working with small projects, we can use the autload function:

use classes\BookProduct;
use classes\NotebookProduct;

require_once 'classes/Product.php';
require_once 'classes/Gadget.php';
require_once 'classes/NotebookProduct.php';
require_once 'classes/BookProduct.php';

function autoloder1($class)
{
    $class = str_replace("\\", '/', $class);
    $file = __DIR__ . "/{$class}.php";
    if(file_exists($file)){
        require_once $file;
    }
}

spl_autoload_register('autoloder1');
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation