php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28566 __autoload does not work when called from a destructor
Submitted: 2004-05-29 03:53 UTC Modified: 2005-04-25 15:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nick at 127tech dot net Assigned: andi (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-06 OS: *
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: nick at 127tech dot net
New email:
PHP Version: OS:

 

 [2004-05-29 03:53 UTC] nick at 127tech dot net
Description:
------------
If I define a destructor that needs __autoload to be  
called, the require_once call inside of __autoload fails.   
If I take the code that failed in the destructor and test  
it in another function in the same class, the __autoload  
call works fine.  
I've noticed that the current working directory is not  
correctly set when __autoload is called from the  
destructor.  It's set to "/", where as my other accesses to  
__autoload have a working directory of where my scripts are  
located.  
I've checked and the file __autoload is trying to  
require_once does exist.  But even if I set the  
full path for the require_once, __autoload fails to work  
when called from the destructor.  
 
Explicitly requiring the file with the external class or 
causing __autoload to require that class before the 
destructor cures the error. 
  
my include_path is set to ".:/usr/local/lib/php".  I've   
tried placing a copy of my class files in  
"/usr/local/lib/php", but that produces the same results.  
  
thanks,  
nick  

Reproduce code:
---------------
function __autoload( $class )
{
 require_once( $class.".php" );
}

class Blah
{
 function __destruct()
 {
   $test = new OutsideClass();
 }
}

$inst = new Blah;

Expected result:
----------------
//no output 

Actual result:
--------------
Fatal error: __autoload() [function.require]: Failed 
opening required 'OutsideClass.php' 
 (include_path='.:/usr/local/lib/php') 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-31 12:04 UTC] derick@php.net
Assigning to Andi, but I'm not sure whether this is a "feature request" or a bug.
 [2004-11-01 14:02 UTC] michali dot sarris at gmail dot com
I am having the same problem. It sure does seem to be a bug since im sure it is not a feature request. I use a few classes to persist an object when it is new or modified. I save the actualy persisting operations for when the object is actualy no more needed. A good method to do this seemed my, was to put the final call in the destructor. But i got a few errors wich i couldn't understand at first. I tried to debug the __autoload method with some file_exist calls. For all the classes the file does exist, but when classes are loaded from a call from the destructor, then every file does not seem to exist, strangely. Can this be fixed please? Thanks.
 [2005-04-25 15:17 UTC] sniper@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC