Search
 
SCRIPT & CODE EXAMPLE
 

PHP

autoloader php

Example #1 Autoload example

This example attempts to load the classes MyClass1 and MyClass2 from the files MyClass1.php and MyClass2.php respectively.
<?php
spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

$obj  = new MyClass1();
$obj2 = new MyClass2(); 
?>

Comment

autoload.php

The introduction of spl_autoload_register() gave programmers 
the ability to create an autoload chain, 
a series of functions that can be called to try and load a class or interface. 

For example:

<?php
function autoloadModel($className) {
    $filename = "models/" . $className . ".php";
    if (is_readable($filename)) {
        require $filename;
    }
}

function autoloadController($className) {
    $filename = "controllers/" . $className . ".php";
    if (is_readable($filename)) {
        require $filename;
    }
}

spl_autoload_register("autoloadModel");
spl_autoload_register("autoloadController");
Comment

PREVIOUS NEXT
Code Example
Php :: php upload multiple files 
Php :: laravel chunk 
Php :: jquery greater than or equal to 
Php :: rest api response 404 wordpress 
Php :: Show all laravel valet folders 
Php :: remove more than one space in string php 
Php :: how to check path laravel 
Php :: how to add column to database in laravel 
Php :: codeigniter 4 delete redirect with data 
Php :: php get property with ~ 
Php :: php functions parameters 
Php :: laravel blade php variable concatenate javascript variable 
Php :: laravel modules 
Php :: display error meaages in laravel blade 
Php :: laravel imap - Get message attachments 
Php :: how run all seeder at once in laravel 
Php :: php pdo error 500 
Php :: call api with php 
Php :: laravel logout all users 
Php :: substr php 
Php :: parse json phph 
Php :: Download any version of xampp 
Php :: laravel add request 
Php :: random string number generator in php codeigniter 
Php :: Movie Name -inurl:(htm|html|php|pls|txt) intitle:index.of “last modified” (mp4|wma|aac|avi) 
Php :: SQLSTATE[42S02] lumen 
Php :: laravel collection first 
Php :: install bcmath php 7.3 ubuntu 
Php :: how do i know if file is empty in php 
Php :: Laravel - Add conditional where clause in query 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =