Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a SplFileObject file handler?

Tags:

php

spl

I'm working with files in PHP using SplFileInfo and SplFileObject. But when I try to "re-open" a file, it yells me :

 SplFileObject::__construct(filemame): failed to open stream: Permission denied

I think I should close my file before re-opening it, but I can't figures how. SplFile* have no close function ?!

like image 328
Gilles Avatar asked Mar 17 '14 08:03

Gilles


1 Answers

You should set SplFileObject to null in order to close the file.

<?php

     $fileHandler = new SplFileObject('file.name');
     //now file.name is open

     $fileHandler = null;
     //file.name is closed.

     $fileHandler2 = new SplFileObject('file.name');
     //file.name is re-opened

?>
like image 153
zkanoca Avatar answered Sep 25 '22 13:09

zkanoca