ID:               30957
 Comment by:       iquito at gmx dot ch
 Reported By:      rueycheng at gmail dot com
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Windows XP
 PHP Version:      5.0.1
 New Comment:

I also encountered this bug, it is very annoying - a class of mine
checks a file with a simple file_exists(), and the file isn't found -
the whole script works if I call the destructor at the very end of it
explicitly (which isn't really the point of having a destructor). it
seems no file functions work at all in the destructor. This bug also
applies to register_shutdown_function, it just seems that as soon as
the "regular" scripts stops, everything that comes after that has
problems with the file system.


Previous Comments:
------------------------------------------------------------------------

[2004-12-02 11:25:07] rueycheng at gmail dot com

The garbage collector may clean up the object prior to its __destruct()
invocation.  Nothing would go wrong if you explicitly *destroy* the
object.

By the way, I tested the code on Redhat 7.3 with the following
configuration.  

$ cat config.nice
#! /bin/sh
#
# Created by configure

'./configure' \
'--with-apxs=/usr/local/apache/bin/apxs' \
'--with-mysql=/usr/local/mysql/' \
'--with-libxml-dir' \
'--enable-dba' \
'--enable-mbstring' \
"$@"

$ diff php.ini ../src/php-5.0.1/php.ini-recommended
353c353
< display_errors = On
---
> display_errors = Off
407c407
< ;error_log = /var/log/php.log
---
> ;error_log = filename
491c491
< include_path = ".:/usr/local/lib/php"
---
> ;include_path = ".:/php/includes"


As a result, two warnings are generated.

[
Warning: file_put_contents(./.bugtest) [function.file-put-contents]:
failed to open stream: Permission denied in
/home/httpd/html/testbed/bugtest.php on line 12

Warning: file_get_contents(./.bugtest) [function.file-get-contents]:
failed to open stream: No such file or directory in
/home/httpd/html/testbed/bugtest.php on line 13
]

Actually I've already enabled the write-permission for the directory. 
The execution of these filesystem functions outside of __destruct() is
OK.

------------------------------------------------------------------------

[2004-12-02 11:01:33] rueycheng at gmail dot com

Description:
------------
Some filesystem functions, like file_put_contents() or fwrite(), don't
work properly in the destructor __destruct().  The following scenario
may looks a bit weird: it appeared that the file is not overwritten or
even created, but PHP does 'read' the content of the imaginary file!

If you uncomment the last line of the code, everything would works
fine.

Thanks.

$ diff php.ini php.ini-dist
288c288
< error_reporting  =  E_ALL
---
> error_reporting  =  E_ALL & ~E_NOTICE & ~E_STRICT
436c436
< include_path = ".;c:\php-5.0.1\PEAR"
---
> ;include_path = ".;c:\php\includes"
450c450
< extension_dir = "c:\php-5.0.1\ext"
---
> extension_dir = "./"
571,573c571,573
< extension=php_mbstring.dll
< extension=php_mcrypt.dll
< extension=php_mhash.dll
---
> ;extension=php_mbstring.dll
> ;extension=php_mcrypt.dll
> ;extension=php_mhash.dll
578c578
< extension=php_mysql.dll
---
> ;extension=php_mysql.dll

Reproduce code:
---------------
<?
class Bug
{
        private $filename;
        
        public function __construct($filename) {
                $this->filename = $filename;
        }
        
        public function __destruct() {
                echo "[";
                file_put_contents($this->filename, 'Gotcha!');
                echo file_get_contents($this->filename);
                echo "]";
        }
}

$bug = new Bug('.bugtest');
//unset($bug);
?>

Expected result:
----------------
[Gotcha!]

(And the file .bugtest under working directory should be created.)

$ cat .bugtest
Gotcha!

Actual result:
--------------
[Gotcha!]

$ cat .bugtest
cat: .bugtest: No such file or directory


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30957&edit=1

Reply via email to