NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.18k stars 14.19k forks source link

PHP environments try to load extensions more than once #127820

Open milibopp opened 3 years ago

milibopp commented 3 years ago

Describe the bug Some PHP environments create warnings like these:

Warning: Module "xml" is already loaded in Unknown on line 0

To Reproduce Steps to reproduce the behavior:

  1. Create a PHP environment with only the XML extension in it like
pkgs.mkShell {
  buildInputs = [
    (pkgs.php.buildEnv {
      extensions = { all, enabled }: [ all.xml ];
    })
  ];
}
  1. Run php -r "", for example.
  2. Observe the warning.

Here is a flake-based gist to help reproduce it.

Expected behavior No warnings should appear.

Additional context This makes it impossible to run a somewhat older Symfony 3.x project of ours. I get warnings about every extension installed and errors about undefined names like this one, when actually trying to run code.

Notify maintainers @globin @talyz

drupol commented 2 years ago

What is the status of this issue ? The linked gist does not exist anymore.

milibopp commented 2 years ago

Fixed the link. (I have changed my GitHub handle, and thus it broke.)

drupol commented 2 years ago

Is the issue still valid ?

milibopp commented 2 years ago

Yes, the problem still exists.

talyz commented 2 years ago

This happens because the xml extension is built-in to the php base package already. IIRC, it had to be built with the base for pear support to work. The easiest solution should be to just not include it in the extension list at all.

guillemcanal commented 2 years ago

Not really the same issue but PHP scripts using the Composer XdebugHandler component to disable the xdebug extension at runtime (like PHPStan or Infection PHP) will load PHP extensions twice.

As demonstrated here : https://gist.github.com/guillemcanal/92f4a97bb31d25522a9a7658a5ff5019

This is caused by the Bash wrapper script created by Nix which export PHP_INI_SCAN_DIR with a fixed value.

guillemcanal commented 2 years ago

A good fix for this issue, would be to check if PHP_INI_SCAN_DIR was already provided.

Here's an example for /nix/store/zn50wlrf73ff12w88ynvha3y0bp7ydpm-php-with-extensions-8.1.1/bin/php

#! /nix/store/iqprjr5k5385bhf1dzj07zwd5p43py1n-bash-5.1-p12/bin/bash -e
export PHP_INI_SCAN_DIR="${PHP_INI_SCAN_DIR:-"/nix/store/zn50wlrf73ff12w88ynvha3y0bp7ydpm-php-with-extensions-8.1.1/lib"}"
"/nix/store/zn50wlrf73ff12w88ynvha3y0bp7ydpm-php-with-extensions-8.1.1/bin/.php-wrapped" "$@"
drupol commented 2 years ago

I added the steps to quickly reproduce the issue locally in the gist.