Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.