Jump to content

spl_autoload (class)


Destramic

Recommended Posts

Im trying to load my classes though my autoloader load method but im having a problem with registering the class (spl_autoload_register) if anyone could tell me why?

 

error:

Fatal error: Uncaught exception 'LogicException' with message 'Passed array does not specify an existing static method' in C:\www\public\index.php:8 Stack trace: #0 C:\www\public\index.php(8): spl_autoload_register(Array) #1 {main} thrown in C:\www\public\index.php on line 8

 

index.php

spl_autoload_extensions('.class.php');
spl_autoload_register(array('Autoloader', 'load'));

 

autoloader.class.php

<?php

class Autoloader_Exception extends Exception {}

class Autoloader
{
public function load()
{

}
}

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/226900-spl_autoload-class/
Share on other sites

public static function load()

 

That solves your problem. If you pass an array with the first parameter being a string it is assumed to be a static call versus:

 

$autoloader = new Autoloader();
spl_autoload_register(array(&$autoloader, 'load'));

 

This will use the existing object and call a method load($class) upon it.

Link to comment
https://forums.phpfreaks.com/topic/226900-spl_autoload-class/#findComment-1170804
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.