php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29072 stack of __autoload handlers
Submitted: 2004-07-09 09:26 UTC Modified: 2005-05-02 11:47 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jasbarne at indiana dot edu Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jasbarne at indiana dot edu
New email:
PHP Version: OS:

 

 [2004-07-09 09:26 UTC] jasbarne at indiana dot edu
Description:
------------
I'm using the __autoload function to load my package's files.  However, if I use another package and that has also implemented __autoload then PHP barfs

Would it be possible to create a stack of __autoload functions?  As an alternative, perhaps we could link __autoload methods to class definitions, and then check class definitions for __autoload functions whenever a class is not found.

Reproduce code:
---------------
<?php
// Test1.php
function __autoload() {}

?>

<?php
//Test2.php
include_once 'Test1.php';
function __autoload() {}

?>

Expected result:
----------------
When user tries to instanciate undefined classes the engine checks all __autoload() functions to try to load the class file.

Actual result:
--------------
Fatal error: Cannot redeclare __autoload() (previously declared in C:\Apache\Apache2\htdocs\DomTools\test.php:5) in C:\Apache\Apache2\htdocs\DomTools\autoload.php on line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-10 14:32 UTC] helly@php.net
That occured to me also. But we cannot do anything before 5.0. Until then you probably need a master __autoload included by auto_prepend_file ini setting. This one would need to handle an array of handlers....in the other files you'd need to register your functions.
 [2005-05-02 11:47 UTC] andrey@php.net
Try ext/spl's mechanism for stacking of autoload functions. For exampel spl_autoload_register() and spl_autoload_call().
Will be available with PHP 5.1.0+
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 03:01:31 2025 UTC