fix: archive a whole directory without a pattern - #912
Merged
blaipr merged 1 commit intoSep 7, 2026
Conversation
ArchiveHandler::compressDirectory(string $directory, ?string $regex = null) offers 'archive the whole directory' as an option, and taking it handed the null straight to PharData::buildFromDirectory(), whose second parameter is declared string. That is a deprecation on PHP 8.5, a fatal on PHP 9, and already a hard error under the test suite's error handler — which is how it surfaced. The one production caller always passes BACKUP_INCLUDE_REGEX, so nothing had reached it. The one-argument form is what 'no pattern' means to Phar, so the argument is passed only when there is one. Corrects #903's description, which called this a TypeError on the strength of the test-suite failure: in ordinary use it is a deprecation and the archive is still built.
blaipr
deleted the
fix/compressing-a-whole-directory-does-not-need-a-regex
branch
September 7, 2026 21:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ArchiveHandler::compressDirectory(string $directory, ?string $regex = null)offers "archive thewhole directory" as an option, and taking it handed the
nullstraight toPharData::buildFromDirectory(), whose second parameter is declaredstring.On PHP 8.5 that is a deprecation, on PHP 9 it is a fatal, and under this suite's error handler it is
already a hard error — which is how it surfaced, while writing the tests for #903. The one
production caller (
BackupFile::backupApp()) always passesBACKUP_INCLUDE_REGEX, so nothing hadreached it.
The one-argument form is what "no pattern" means to Phar, so the argument is passed only when there
is one.
Correcting the record
#903's description called this a
TypeErroron the strength of the test-suite failure. It is adeprecation notice in ordinary use — the archive is still built, with the null read as an empty
pattern. The consequence is a PHP 9 upgrade turning it into a fatal, not a break today. The rest of
that PR is unaffected.
While measuring this I also checked what Phar does with each spelling, because the answer decides
the fix: with the archive re-opened,
buildFromDirectory($dir),…($dir, '')and…($dir, '/.*/')all archive everything, and a narrower pattern filters as expected. An earlier reading of "the
one-argument form archives nothing" was an artefact of counting entries before the archive was
closed.
Test
aDirectoryCanBeArchivedWithNoPatternAtAllasserts the contents rather than the absence of anerror — the point is that the option still archives everything. It fails against the old call.