Skip to content

php -z does not seem to work at all #17740

Closed
@BenMorel

Description

@BenMorel

Description

The examples below use the following test.php script:

<?= extension_loaded('Zend OPcache') ? "OPcache loaded\n" : "OPcache NOT loaded\n";

The -d zend_extension option accepts either a file name with or without the .so extension, or an absolute path:

$ php -n -d zend_extension=opcache test.php
OPcache loaded
$ php -n -d zend_extension=opcache.so test.php
OPcache loaded
$ php -n -d zend_extension=/usr/lib/php/20230831/opcache.so test.php
OPcache loaded

The -z option, on the other hand, does not seem to accept a file name:

$ php -n -z opcache test.php
Failed loading opcache:  opcache: cannot open shared object file: No such file or directory
OPcache NOT loaded
$ php -n -z opcache.so test.php
Failed loading opcache.so:  opcache.so: cannot open shared object file: No such file or directory
OPcache NOT loaded

It does not complain when passing an absolute path, but still does not load the extension:

$ php -n -z /usr/lib/php/20230831/opcache.so test.php
OPcache NOT loaded

Furthermore, its behaviour becomes really strange when you specify both -d zend_extension and -z:

$ php -n -d zend_extension=opcache -z opcache test.php
Failed loading opcache:  opcache: cannot open shared object file: No such file or directory
OPcache loaded
$ php -n -d zend_extension=opcache.so -z opcache.so test.php
Cannot load Zend OPcache - it was already loaded
OPcache loaded
$ php -n -d zend_extension=/usr/lib/php/20230831/opcache.so -z /usr/lib/php/20230831/opcache.so test.php
Cannot load Zend OPcache - it was already loaded
OPcache loaded

In the last 2 runs, it now says that the extension was already loaded, even though specifying -z alone did not load the extension.

Is the -z argument broken? Should it be removed from php, as it's redundant with -d zend_extension anyway?

PHP Version

PHP 8.1, 8.2, 8.3, 8.4

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