[php-src] Issue #18937: Files tar extracted from Phar have Jan 1 1970 as date
| From: | emteknetnz | Date: | Wed, 25 Jun 2025 07:51:08 +0000 |
| Subject: | [php-src] Issue #18937: Files tar extracted from Phar have Jan 1 1970 as date | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250318@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18937
Author: emteknetnz
### Description
The following code:
```php
<?php
// run.php
// run
touch myfile in terminal first
$phar = new PharData('archive.tar');
$phar->addFile('myfile');
// Adding explict options makes no difference
// $phar = new PharData(
// $filename,
// FilesystemIterator::SKIP_DOTS|FilesystemIterator::UNIX_PATHS,
// null,
// Phar::TAR
// );
// Name file a.tar.gz if using this option, tar -xzf has the same date issue
// $phar->compress(Phar::GZ);
// Note that buildFromDirectory() seems to have the same issue:
// $phar->buildFromDirectory()
//
// Also note that extractTo() work as expected i.e. has today date
// $phar->extractTo('. 'myfile');
```
```bash
touch myfile
ls -al | grep myfile
php run.php
tar -xf archive.tar
ls -al | grep myfile
```
Resulted in this output:
```
-rw-rw-r-- 1 myuser mygrp 0 Jun 25 19:33 myfile
-rw-rw-r-- 1 myuser mygrp 0 Jan 1 1970 myfile
```
But I expected this output instead:
```
-rw-rw-r-- 1 myuser mygrp 0 Jun 25 19:33 myfile
-rw-rw-r-- 1 myuser mygrp 0 Jun 25 19:33 myfile
```
### PHP Version
```plain
# DOES NOT AS EXPECTED:
PHP 8.4.8 (cli) (built: Jun 9 2025 13:50:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.8, Copyright (c) Zend Technologies
with Zend OPcache v8.4.8, Copyright (c), by Zend Technologies
PHP 8.3.22 (cli) (built: Jun 9 2025 14:03:36) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.22, Copyright (c) Zend Technologies
with Zend OPcache v8.3.22, Copyright (c), by Zend Technologies
PHP 8.2.28 (cli) (built: Mar 13 2025 18:13:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.28, Copyright (c) Zend Technologies
with Zend OPcache v8.2.28, Copyright (c), by Zend Technologies
# WORKS AS EXPECTED:
PHP 8.1.32 (cli) (built: Mar 13 2025 18:27:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.32, Copyright (c) Zend Technologies
with Zend OPcache v8.1.32, Copyright (c), by Zend Technologies
```
### Operating System
Ubuntu 24.04