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 :: popular cms 
Php :: assigning variable in php 
Php :: secure random number php 
Php :: ajax search request 
Php :: post data to another page contact form 7 
Php :: array marge in php 
Php :: codeigniter validation text length 
Php :: utc time php 
Php :: round to 0.5 php 
Php :: How do I get a YouTube video thumbnail from the YouTube API? 
Php :: how to use attempt in laravel 
Php :: php remove value from array 
Php :: Disabling Caching of Queries Laravel Model Cache 
Php :: php execute a background process 
Php :: laravel create many to many table 
Php :: construct php 
Php :: if home else php wordpress 
Php :: Compiling multiple CSS into ONE CSS with Laravel MIX 
Php :: where clause in laravel 
Php :: acosh php 
Php :: php docker offical apache 
Php :: laravel manually authenticate user 
Php :: types of method in api 
Php :: make resource in laravel 
Php :: replace last two characters string php 
Php :: insert array values in database using codeigniter 
Php :: laravel check if environment is production 
Php :: Rename route resource in laravel 
Php :: compare two datetime php 
Php :: Function create_function() is deprecated in 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =