php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49674 spl_autoload not auto loading
Submitted: 2009-09-25 19:35 UTC Modified: 2009-09-26 12:12 UTC
From: lists at reptiliannature dot org Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.0 OS: Linux 2.6.28-15
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lists at reptiliannature dot org
New email:
PHP Version: OS:

 

 [2009-09-25 19:35 UTC] lists at reptiliannature dot org
Description:
------------
I have been trying to use spl_autoload() to load a class located in the same folder. My include path is set to ".".  The class file exists in the same folder, and the class has the same name as the file without the .php extension.

The loading does not work. 

Reproduce code:
---------------
File test.php
<?php
set_include_path('.');
var_dump(get_include_path());

$className = 'ClassA';
spl_autoload($className);
$ins = new $className;
echo $ins->val.'<br>';

?>
File ClassA.php
<?php class ClassA { var $val = 'Hello from class "ClassA"'; } ?>

Expected result:
----------------
string(1) "."

Hello from class "ClassA"

Actual result:
--------------
string(1) "."

Fatal error: Uncaught exception 'LogicException' with message 'Class ClassA could not be loaded' in /home/michael/src/php/tests/spl_autoload/test.php:7
Stack trace:
#0 /home/michael/src/php/tests/spl_autoload/test.php(7): spl_autoload('ClassA')
#1 {main}
  thrown in /home/michael/src/php/tests/spl_autoload/test.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-25 21:52 UTC] jani@php.net
Class name is lowercased before any lookup is done. Hence, your file 
needs to be in lowercase as well. See also bug #48129
 [2009-09-25 21:53 UTC] jani@php.net
File NAME of course needs to be lowercase. Not the file contents. :D
 [2009-09-26 12:12 UTC] lists at reptiliannature dot org
Thanks for letting me know.  I appreciate it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 05:01:29 2024 UTC