Bug #80915 [Opn->Csd]: Taking a reference to $_SERVER hides it's values from phpinfo()

From: Date: Tue, 30 Mar 2021 11:57:50 +0000
Subject: Bug #80915 [Opn->Csd]: Taking a reference to $_SERVER hides it's values from phpinfo()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233062@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80915&edit=1

 ID:                 80915
 Updated by:         cmb@php.net
 Reported by:        donatj at gmail dot com
 Summary:            Taking a reference to $_SERVER hides it's values
                     from phpinfo()
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   All
 PHP Version:        8.0.3
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Fixed as <https://github.com/php/php-src/commit/206fd35a98375522a53818ec4ef6e0585b1055dd>.


Previous Comments:
------------------------------------------------------------------------
[2021-03-29 19:02:08] rowan dot collins at gmail dot com

The following pull request has been associated:

Patch Name: Handle reference zvals when outputting superglobals in phpinfo()
On GitHub:  https://github.com/php/php-src/pull/6818
Patch:      https://github.com/php/php-src/pull/6818.patch

------------------------------------------------------------------------
[2021-03-29 18:11:37] rowan dot collins at gmail dot com

Simpler reproduction case:

 php -r '$foo =& $_SERVER; phpinfo(INFO_VARIABLES);'

This works as expected on 5.6, but fails on 7.0 - which makes sense, as the implementation of
references was heavily changed in that version.

------------------------------------------------------------------------
[2021-03-29 17:50:31] donatj at gmail dot com

It's not an entirely pointless use of references, just mostly.

If $_SERVER should change after declaring an instance from globals you might want to inherit those
changes

------------------------------------------------------------------------
[2021-03-29 17:40:02] ecegefef dot wfwfwg at fff dot gg

clap on the fingers for pointless use of references and than even for special handled magic vars

------------------------------------------------------------------------
[2021-03-29 17:25:48] donatj at gmail dot com

Description:
------------
$_SERVER disappeared from our admin phpinfo page, after a bit of poking I figured 
out a middleware we're using takes a reference to $_SERVER.

It only reads, doesn't write to it at all - but it breaks phpinfo.

This can be seen in my given example code where simply:

$foo =& $_SERVER;

breaks phpinfo's variable output


Test script:
---------------
<?php

echo "---- Expected Output ----\n\n";

\phpinfo(INFO_VARIABLES);

echo "\n\n---- Actual Broken Output ----\n\n";

$foo =& $_SERVER;

\phpinfo(INFO_VARIABLES);

echo "\n\n---- Proof that \$_SERVER isn't broken ----\n\n";

print_r($_SERVER);


Expected result:
----------------
(truncated to relevant output)

phpinfo()

PHP Variables

Variable => Value
$_SERVER['TMPDIR'] => /var/folders/dr/cpm01_51333c1px2yzc8qr9xq1kth0/T/
$_SERVER['__CF_USER_TEXT_ENCODING'] => 0x6E196A00:0x0:0x0
$_SERVER['HOME'] => /Users/jdonat
$_SERVER['SHELL'] => /bin/zsh
$_SERVER['Apple_PubSub_Socket_Render'] =>
/private/tmp/com.apple.launchd.d1nNRxAouL/Render
$_SERVER['SSH_AUTH_SOCK'] => /private/tmp/com.apple.launchd.7DMDsXS1qP/Listeners
$_SERVER['PATH'] => /usr/bin:/bin:/usr/sbin:/sbin
$_SERVER['LOGNAME'] => jdonat
$_SERVER['DISPLAY'] =>
/private/tmp/com.apple.launchd.DHo7IG8khp/org.macosforge.xquartz:0
$_SERVER['XPC_SERVICE_NAME'] => com.electron.standard-otter.146872
$_SERVER['USER'] => jdonat
$_SERVER['XPC_FLAGS'] => 0x0
$_SERVER['PHP_SELF'] => -
$_SERVER['SCRIPT_NAME'] => -
$_SERVER['SCRIPT_FILENAME'] => 
$_SERVER['PATH_TRANSLATED'] => 
$_SERVER['DOCUMENT_ROOT'] => 
$_SERVER['REQUEST_TIME_FLOAT'] => 1617038447.9799
$_SERVER['REQUEST_TIME'] => 1617038447
$_SERVER['argv'] => Array
(
    [0] => -
)

$_SERVER['argc'] => 1

Actual result:
--------------
(truncated to relevant output)

phpinfo()

PHP Variables

Variable => Value


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80915&edit=1


Thread (6 messages)

« previous php.bugs (#233062) next »