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");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();
?>
Also in PHP:
- echo fread($myfile,filesize("webdictionary.txt"));
- add datetime to datetime php
- erroring reporting all in php
- WooCommerce Add Long Description to Products on Shop Page with Character limit
- centos excecutable php
- Get the visitors ip adress php
- composer require php '^5.4'
- creat folder in php
- error php code
- Laravel 8 Resource
- create database in phpmyadmin
- date formate php
- date function is one day after strtotime
- add redirect php
- $heure = date('H'); php 5
- buat table seeder laravel
- $date php
- check if array is duplicate and get the latest values php
- echo current time user php
- determine the date format from a string php
- error_reporting in php.ini file
- Notice: Array to string conversion php
- add d4 days in php\
- check string in string php