Jump to content

[SOLVED] proper usage of spl_autoload_extensions ???


Recommended Posts

I'm trying to figure out what's the point of this function!!

 

I registered the extensions I'm using ('.class.php,.php') and correctly set up my include path but the I get warnings saying that "path/to/file" can't be found.  (even though the class is located in path/to/file.class.php) I also use some 3rd party components that are named "file.php" so I've got to account for both.

 

Now, I've figured it out and my autoloader works fine, but I'm really just wondering what's the point of spl_autoload_extensions if I have to manually specify the extensions myself??  The more intuitive approach would be that you could leave out the extensions and it would automatically search for both types right?

It defaults to <class name in lowercase>.inc or <class name in lowercase>.php.

 

I realize that!  I've changed it to use:

<class name in lowercase>.class.php and <class name in lowercase>.php

 

But in my include statement in my autoloader i still end up having to manually specify the extension if not it doesnt find my classes....

This function can modify and check the file extensions that the built in __autoload() fallback function spl_autoload() will be using.

 

If you make your own autoloading function, there will not be used any fallback.

 

So basically if I have no autoloader expilcitly defined but I define spl_autoload_extensions() then the fallback will look in my include_path for corresponding files with the defined extensions?

This function is intended to be used as a default implementation for __autoload(). If nothing else is specified and autoload_register() is called without any parameters then this functions will be used for any later call to __autoload().
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.