Skip to content

Exclude default extensions for PHP ^8.1 #8273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2023

Conversation

NicolaeIotu
Copy link
Contributor

@NicolaeIotu NicolaeIotu commented Nov 29, 2023

Some extensions are included with PHP. It is better to exclude them from requirements as these are most likely unavailable from package managers.

The details of the extensions can be viewed at https://www.php.net/manual/en/extensions.alphabetical.php.
I recommend to open a new tab for each extension of interest and visit section Installation which indicates if it is shipped by default or not.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@@ -12,7 +12,6 @@
"require": {
"php": "^8.1",
"ext-intl": "*",
"ext-json": "*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is part of the PHP core.

composer.json Outdated
"ext-gd": "If you use Image class GDHandler",
"ext-imagick": "If you use Image class ImageMagickHandler",
"ext-libxml": "If you use TestResponse",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

This extension requires » libxml >= 2.9.0 as of PHP 8.0. libxml >= 2.6.0 prior to PHP 8.0.
https://www.php.net/manual/en/libxml.requirements.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true.
However PHP handles downstream dependencies for you. There is no need to check for the required libraries downstream.

If PHP states

The libxml extension is enabled by default,

https://www.php.net/manual/en/libxml.installation.php, that's all there is to check.

Let's dig deeper:

php=$(which php)
php_pkg=$(rpm -qf $php) 
rpm -q "${php_pkg}" --requires

, or
rpm -q "${php_pkg}" --requires | grep -i xml

Finally:
(there is no package for libxml)
dnf search libxml | grep -i php
(included by default)
php -r "phpinfo();" | grep -i xml

Cannot check the same on Windows and others, but it should be similar.
So the remarks regarding http://www.xmlsoft.org/ do not apply unless there is a different approach from PHP on other operating systems. I'm using Fedora.

composer.json Outdated
@@ -38,21 +37,16 @@
},
"suggest": {
"ext-curl": "If you use CURLRequest class",
"ext-dom": "If you use TestResponse",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

This extension requires the libxml PHP extension.
https://www.php.net/manual/en/dom.requirements.php

composer.json Outdated
"ext-exif": "If you run Image class tests",
"ext-fileinfo": "Improves mime type detection for files",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. not part of the PHP core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows exception. Okay.

composer.json Outdated
"ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
"ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
"ext-mysqli": "If you use MySQL",
"ext-oci8": "If you use Oracle Database",
"ext-pgsql": "If you use PostgreSQL",
"ext-readline": "Improves CLI::input() usability",
"ext-redis": "If you use Cache class RedisHandler",
"ext-simplexml": "If you format XML",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension requires the libxml PHP extension.

composer.json Outdated
"ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
"ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
"ext-mysqli": "If you use MySQL",
"ext-oci8": "If you use Oracle Database",
"ext-pgsql": "If you use PostgreSQL",
"ext-readline": "Improves CLI::input() usability",
"ext-redis": "If you use Cache class RedisHandler",
"ext-simplexml": "If you format XML",
"ext-sqlite3": "If you use SQLite3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, so this goes for "Can be disabled" remarks.

The following:

This extension is enabled by default. It may be disabled by using the following option at compile time: --disable-simplexml

, translates to: official versions of PHP include simplexml, but when building PHP from source there is the option to disable simplexml.
Basically simplexml it's always there with the official versions of PHP.

Framework decision required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add the critical part.
The extensions which can be disabled are not supplied by the package managers (i.e. dnf).

In case someone builds PHP from source using i.e. --disable-simplexml and later on decides he needs ext-simplexml, then he has to build from source simplexml. Now, this is odd indeed.

Copy link
Member

@kenjis kenjis Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not linux distribution's package names, but PHP extensions.
I think it is no problem to list those that are listed in composer.

$ composer show --platform | grep ^ext
ext-bcmath                 8.1.26   The bcmath PHP extension
ext-bz2                    8.1.26   The bz2 PHP extension
ext-calendar               8.1.26   The calendar PHP extension
ext-ctype                  8.1.26   The ctype PHP extension
ext-curl                   8.1.26   The curl PHP extension
ext-date                   8.1.26   The date PHP extension
ext-dba                    8.1.26   The dba PHP extension
ext-dom                    20031129 The dom PHP extension
ext-exif                   8.1.26   The exif PHP extension
ext-ffi                    8.1.26   The FFI PHP extension
ext-fileinfo               8.1.26   The fileinfo PHP extension
ext-filter                 8.1.26   The filter PHP extension
ext-ftp                    8.1.26   The ftp PHP extension
ext-gd                     8.1.26   The gd PHP extension
ext-gettext                8.1.26   The gettext PHP extension
ext-gmp                    8.1.26   The gmp PHP extension
ext-hash                   8.1.26   The hash PHP extension
ext-iconv                  8.1.26   The iconv PHP extension
ext-imagick                3.7.0    The imagick PHP extension
ext-intl                   8.1.26   The intl PHP extension
ext-json                   8.1.26   The json PHP extension
ext-ldap                   8.1.26   The ldap PHP extension
ext-libxml                 8.1.26   The libxml PHP extension
ext-mbstring               8.1.26   The mbstring PHP extension
ext-memcached              3.2.0    The memcached PHP extension
ext-mysqli                 8.1.26   The mysqli PHP extension
ext-mysqlnd                0        The mysqlnd PHP extension (actual version: mysqlnd 8.1.26)
ext-odbc                   8.1.26   The odbc PHP extension
ext-openssl                8.1.26   The openssl PHP extension
ext-pcntl                  8.1.26   The pcntl PHP extension
ext-pcre                   8.1.26   The pcre PHP extension
ext-pdo                    8.1.26   The PDO PHP extension
ext-pdo_dblib              8.1.26   The pdo_dblib PHP extension
ext-pdo_mysql              8.1.26   The pdo_mysql PHP extension
ext-pdo_odbc               8.1.26   The PDO_ODBC PHP extension
ext-pdo_pgsql              8.1.26   The pdo_pgsql PHP extension
ext-pdo_sqlite             8.1.26   The pdo_sqlite PHP extension
ext-pgsql                  8.1.26   The pgsql PHP extension
ext-phar                   8.1.26   The Phar PHP extension
ext-posix                  8.1.26   The posix PHP extension
ext-pspell                 8.1.26   The pspell PHP extension
ext-readline               8.1.26   The readline PHP extension
ext-redis                  5.3.7    The redis PHP extension
ext-reflection             8.1.26   The Reflection PHP extension
ext-session                8.1.26   The session PHP extension
ext-shmop                  8.1.26   The shmop PHP extension
ext-simplexml              8.1.26   The SimpleXML PHP extension
ext-soap                   8.1.26   The soap PHP extension
ext-sockets                8.1.26   The sockets PHP extension
ext-sodium                 8.1.26   The sodium PHP extension
ext-spl                    8.1.26   The SPL PHP extension
ext-sqlite3                8.1.26   The sqlite3 PHP extension
ext-sqlsrv                 5.11.0   The sqlsrv PHP extension
ext-sysvmsg                8.1.26   The sysvmsg PHP extension
ext-sysvsem                8.1.26   The sysvsem PHP extension
ext-sysvshm                8.1.26   The sysvshm PHP extension
ext-tidy                   8.1.26   The tidy PHP extension
ext-tokenizer              8.1.26   The tokenizer PHP extension
ext-xdebug                 3.2.1    The xdebug PHP extension
ext-xml                    8.1.26   The xml PHP extension
ext-xmlreader              8.1.26   The xmlreader PHP extension
ext-xmlwriter              8.1.26   The xmlwriter PHP extension
ext-xsl                    8.1.26   The xsl PHP extension
ext-zend-opcache           8.1.26   The Zend OPcache PHP extension
ext-zip                    1.19.5   The zip PHP extension
ext-zlib                   8.1.26   The zlib PHP extension

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there is ext-json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is not needed.

@NicolaeIotu
Copy link
Contributor Author

You can test the validity of this PR with a fresh install, like a fresh VM or bare metal install, clean OS install. Alternatively you can make a thorough uninstall and try from scratch.

It's a simple as that - on a fresh install it is not possible to find official PHP extensions:

  • ctype
  • dom
  • fileinfo
  • iconv
  • sqlite3
  • xmlwriter
  • json
  • libxml
  • simplexml

However these are included in the requirements. It is obvious that since these are provided by default with PHP there will be no issues unless the user tries to install those dependencies and it is not able to find them using the package manager.

Automated installers will have to take into account the fact that some requirements are just unavailable, skip install errors and hope everything will go well. This is actually where I'm pointing to:

  • deploying CodeIgniter
  • running composer install
  • scripting to download extensions -> this will have to take into account the fact that the requirements are not up to date, errors will trigger, skip errors, hope all works well ...

The requirements are not rigorously correct as they are at the moment.

@michalsn
Copy link
Member

Personally, I see no harm in having all these extensions specified. They can be helpful with edge cases when PHP is compiled from source.

@kenjis
Copy link
Member

kenjis commented Nov 30, 2023

@NicolaeIotu You seem to be confusing OS packages with PHP extensions.
You can check your PHP extensions with php -m or composer show --platform.
All you need to do is to install missing extensions.

Is there an automated installer that behaves in the way you are concerned about?

@NicolaeIotu
Copy link
Contributor Author

When I specified for example ctype it is because the Linux package is most likely not named ext-ctype. You have to search for it using ctype:
dnf search ctype | grep -i php
Obviously, because it's shipped by default you won't be able to find anything.

I'm gonna go ahead and assume you have ext-imagick installed.
Adjust below for your Linux:

php -m | grep -i imagick

(this should show imagick)

sudo dnf remove -y php-pecl-imagick.x86_64
php -m | grep -i imagick

(imagick missing)

sudo dnf install -y php-pecl-imagick.x86_64
php -m | grep -i imagick

(this should show imagick)

In this case imagick is an extension which may be required with composer.json. The users will search for it and install corresponding package (which will provide ext-imagick as viewed by php to clarify).
The same user will find nothing when searching for ctype (and the other extensions listed by me), yet you put it in composer.json. This is the whole point of this PR. I cannot possibly put it in an easier to understand format.

Returning to practical stuff, since it is not acceptable for you to exclude default extensions, the only thing which remains to decide is if at least the extension which is part of PHP core can be eliminated from the requirements. That's ext-json.
If it's not than we can close this PR.

@kenjis
Copy link
Member

kenjis commented Dec 1, 2023

The Linux packages are irrelevant. The package maintainer can create these packages as s/he likes.

This is a Composer configuration and is about PHP extensions.
If you run composer show --platform, you can see PHP extensions that are already installed.
So you don't need to install installed extensions.

This configuration is for Composer. If you have missing extensions, Composer reports errors when you install a composer package that requires the extentions.
It is not for searching Linux packages.

If you have an automated installer that reads composer.json and tries to find Linux packages from the ext-* listed, then the installer implementation is wrong.

@NicolaeIotu
Copy link
Contributor Author

Alright. All good. Awesome. Let's return to the PR. Anything else will only clutter judgement.

Found unifying logic.
When running composer show --platform we get a list of the platform extensions. Quite a lot of these are used by CodeIgniter and not included in the composer.json because of some reasons. This is where we can find logic pointing to the correct answer to this PR.

Let's take a few packages which are used by CodeIgniter: ext-reflection and ext-sodium. What is the precise reason for which composer.json does not include them? Why are these not included in composer.json?
Now let's check:

The answer is that these are bundled with php or part of the core. It's pointless to include them. The same applies for many other extensions used by CodeIgniter.
So the logic was followed up to a point. Now composer.json needs another update.

@kenjis
Copy link
Member

kenjis commented Dec 1, 2023

ext-sodium is not a PHP core. I send PR #8281.
It was just missing.

And yes, we don't need PHP core extensions that are not disabled.

@NicolaeIotu
Copy link
Contributor Author

I see. You probably need to go through and check the rest of the list because I only picked 2 random extensions for my example.

And yes, we don't need PHP core extensions that are not disabled.

This means you have to exclude ext-json which is core and always enabled. There's a commit above for this change.
https://www.php.net/manual/en/json.installation.php

@kenjis
Copy link
Member

kenjis commented Dec 1, 2023

This means you have to exclude ext-json which is core and always enabled. There's a commit above for this change.

Yes, we now require PHP 8.1+, so we don't need it.
Also please update admin/framework/composer.json.

@kenjis kenjis added the 4.5 label Dec 1, 2023
@NicolaeIotu
Copy link
Contributor Author

Okay. Done with admin/framework/composer.json.
Thank you!

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MGatner MGatner merged commit 688081d into codeigniter4:4.5 Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants