phpunit: Running phpunit-7.4.0.phar with phpdbg throws NOTICE

Q A
PHPUnit version 7.4.0
PHP version phpdbg 7.2.10
Installation Method PHAR

phpunit installed via phive. When calling phpdbg -qrr /usr/local/bin/phpunit the folling NOTICE is shown:

[PHP Notice:  Undefined index: _SERVER in /usr/local/bin/phpunit on line 18]

Guess that $_SERVER is simply not set in phpdbg?

This line raises the notice, I guess in build/binary-phar-autoload.php.in:

if (__FILE__ === realpath($GLOBALS['_SERVER']['SCRIPT_NAME'])) {

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry, but this does not look like a PHPUnit problem to me.

According to @krakjoe and @nikic, there might be an interoperability issue between PHPDBG and Xdebug here that hides a problem in PHPUnit’s code. That problem is that one cannot rely on $_SERVER being defined.

CC @derickr on the off chance that is relevant to Xdebug development.

Without Xdebug I can reproduce it:

$ phpdbg --version
phpdbg 0.5.0 (built: Feb  5 2019 13:10:03)
PHP 7.3.2, Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies
$ phpdbg -d auto_globals_jit=On -qrr phpunit-8.phar --version
[PHP Notice:  Undefined index: _SERVER in /home/sb/phpunit-8.phar on line 18]
$ phpdbg -d auto_globals_jit=Off -qrr phpunit-8.phar --version
PHPUnit 8.0.1 by Sebastian Bergmann and contributors.

It’s not only a docker issue. Here’s a reproducer that also fails on OS X:

wget -O phpunit https://phar.phpunit.de/phpunit-8.phar
phpdbg -qrr phpunit --version

[PHP Notice: Undefined index: _SERVER in /Users/kuba/phpunit on line 18]

You can run phpunit with phpdbg setting directly auto_globals_jit variable like this

phpdbg -dauto_globals_jit=Off -qrr /usr/local/bin/phpunit

I just ran into this myself in exactly the same scenario. Found this:

https://odd.blog/2015/02/12/php-notice-undefined-variable-_server-in/

Setting “auto_globals_jit = Off” does seem to fix it.