Skip to content

Files tar extracted from Phar archive have Jan 1 1970 as date #18937

Open
@emteknetnz

Description

@emteknetnz

Description

The following code:

<?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() works as expected i.e. has today date
// $phar->extractTo('. 'myfile');
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

# DOES NOT WORK 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions