If you use SplFileObject for the same file which
you want to rename you have to remove SplFileObject objec first.
<?php
$filePath = 'testFile.txt';
$fileObj = new SplFileObject( $filePath );
rename( $filePath, 'newName.txt' );
// You will get - Permission denied error
$filePath = 'testFile.txt';
$fileObj = new SplFileObject( 'filePath.txt' );
$fileObj = null;
rename( $filePath, 'newName.txt' );
// and now it is working.
?>