I have multiple versions of PHP using brew. When I want to switch between for example from PHP 7.4 to PHP 8.1 I use this command
brew unlink [email protected] && brew link [email protected]
When I download Xdebug for PHP 8.1 I use
pecl install xdebug
It would install Xdebug's latest version until now. So if I write
pecl list
I get
Package Version State
imagick 3.7.0 stable
xdebug 3.2.2 stable
When I open /usr/local/etc/php/8.1/php.ini I get
zend_extension="xdebug.so"
That's fine until now.
Now the problem is when I want to install a lower version for my PHP 7.4 (because the newer version of Xdebug is not compatible with PHP 7.4). So according to this page I should download at most xdebug-3.1 for PHP 7.
So I will switch to PHP 7 using
brew unlink [email protected] && brew link [email protected]
then I download a compatible Xdebug version with PHP 7.4 using this command
pecl install xdebug-3.1.6
It will be downloaded fine, but I get this issue whenever I use PHP, e.g php -v
Failed loading /usr/local/opt/[email protected]/pecl/20210902/xdebug.so: dlopen(/usr/local/opt/[email protected]/pecl/20210902/xdebug.so, 0x0009): symbol not found in flat namespace (_instanceof_function_slow)
I guess because it didn't know the path for Xdebug.
If I open /usr/local/etc/php/7.4/php.ini I get
zend_extension="xdebug.so"
I tried to change the path in php.ini in PHP 7 to /usr/local/opt/[email protected]/pecl/20210902/xdebug.so because there is an Xdebug file in this path, but the problem remains.
How can I fix this problem?
You are loading
xdebug.socompiled for the wrong PHP version. For PHP 7.4 you should see if you have.../pecl/20190902/xdebug.sofile. Then check your active php.ini to see where the extensions are loaded from, seeextension_dirphp.ini directive.Details:
The Failed loading error tells me two things.
First, the loaded .so file depends on the exported function
_instanceof_function_slow. This is something that is present in the PHP-8 branch but not in the PHP 7.4 brnach.The second is the API Version in the path
/usr/local/opt/[email protected]/pecl/20210902/xdebug.so. The20210902API version corresponds to PHP 8.1, where as PHP 7.4 uses 20190902. I was not able to find a list on the official site (aside from looking at the source), but here is one link that lists the versions for reference.My guess is that brew link/unlink keeps the same pecl directory (
/usr/local/opt/[email protected]/pecl==/usr/local/opt/[email protected]/pecl) and/or that the php.ini needs adjusting.To debug things I'd suggest the following:
pecl listwhen PHP 7.4 is active/usr/local/opt/[email protected]/pecland/usr/local/opt/[email protected]/peclif there are more API version folders (looking for20190902and20210902)php -i | grep extension_dirphp -i | grep -i peclzend_extension="/usr/local/opt/[email protected]/pecl/20190902/xdebug.so"