To create password protected archive in PHP >= 7.2 use:
<?php
$zip->setEncryptionName('test.txt', ZipArchive::EM_AES_256, 'test');
?>
Based on example from the documentation:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->setEncryptionName('test.txt', ZipArchive::EM_AES_256, 'passw0rd');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>