Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/zip/BuiltinClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ final class BuiltinClasses
{
public static function register(Context $ctx): void
{
if (!ZipExtensionPolicy::advertisesExtension()) {
return;
}

$before = array_keys($ctx->classes);
VmZipArchive::registerClass($ctx);
foreach (array_diff(array_keys($ctx->classes), $before) as $lc) {
Expand Down
8 changes: 7 additions & 1 deletion ext/zip/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
/**
* zip extension module entry (php-src ext/zip/php_zip.c; issue #5869).
*
* ZipArchive open/extract in ext/zip PHP (issues #3337, #6414); v1 skeleton enables class_exists() and inventory.
* ZipArchive parity tracked in #3337; register under {@see standard} so
* extension_loaded('zip') stays false until libzip ships (#11676).
*/
class Module extends ModuleAbstract
{
public function getExtensionName(): string
{
return 'standard';
}

public function init(Runtime $runtime): void
{
parent::init($runtime);
Expand Down
20 changes: 20 additions & 0 deletions ext/zip/ZipExtensionPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace PHPCompiler\ext\zip;

use PHPCompiler\ext\standard\ModuleRegistry;

/**
* ext/zip surface advertisement — php-src ext/zip/php_zip.c (#11676).
*
* ZipArchive registers only when {@see ModuleRegistry::extensionLoaded}('zip') is true (#3337).
*/
final class ZipExtensionPolicy
{
public static function advertisesExtension(): bool
{
return ModuleRegistry::extensionLoaded('zip');
}
}
13 changes: 13 additions & 0 deletions test/compliance/cases/stdlib/extension_loaded_zip_phantom.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
stdlib extension_loaded('zip') false until libzip implemented (#11676, ext/zip/php_zip.c)
--FILE--
<?php
declare(strict_types=1);

echo 'loaded=', (int) extension_loaded('zip'), "\n";
echo 'in_list=', (int) in_array('zip', get_loaded_extensions(), true), "\n";
echo 'class=', (int) class_exists('ZipArchive'), "\n";
--EXPECT--
loaded=0
in_list=0
class=0
29 changes: 29 additions & 0 deletions test/repro/maintainer_gap_extension_loaded_zip_phantom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/**
* Issue #11676 — extension_loaded('zip') phantom probe (ext/zip/php_zip.c).
*/

$loaded = extension_loaded('zip') ? 'yes' : 'no';
$zipArchive = class_exists('ZipArchive') ? 'yes' : 'no';

$probe = 'absent';
if ($zipArchive === 'yes') {
try {
new ZipArchive();
$probe = 'ok';
} catch (Throwable $e) {
$probe = $e::class;
}
}

echo "loaded={$loaded} ZipArchive={$zipArchive} probe={$probe}\n";

if ($loaded !== 'no' || $zipArchive !== 'no') {
echo "fail: zip probe must be absent until ext/zip parity (#3337)\n";
exit(1);
}

echo "ok\n";