|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-19 20:43 UTC] samuel at slbdata dot se
Description:
------------
Comparing a string in the $_SERVER superglobal using the strict equality operator (===) always fails, even though both types are strings. $_GET and other variables work fine.
I'm using the php.ini-recommended file, with no changes except for display_(startup_)errors which are enabled. My locale is sv_SE.UTF-8 (the LANG environment variable is set to this value)
This used to work fine in php6.0-200804260630
Reproduce code:
---------------
<?php
$rm = $_SERVER['REQUEST_METHOD'];
echo "Type is: ".gettype($rm)." <br />\n";
if (($rm !== 'GET') && ($rm == 'GET')) {
echo "Bug! <br />\n";
} else {
echo "Correct behaviour! <br />\n";
}
$sp = $_SERVER['SERVER_PROTOCOL'];
echo "Type is: ".gettype($sp)." <br />\n";
if (($sp !== 'HTTP/1.1') && ($sp == 'HTTP/1.1')) {
echo "Bug! <br />\n";
} else {
echo "Correct behaviour! <br />\n";
}
Expected result:
----------------
Type is: string
Correct behaviour!
Type is: string
Correct behaviour!
Actual result:
--------------
Type is: string
Bug!
Type is: string
Bug!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 14:00:01 2025 UTC |
<?php $str = 'Test'; var_dump($str); echo "<br />\n"; $rm = $_SERVER['REQUEST_METHOD']; var_dump($rm); echo "<br />\n"; $sp = $_SERVER['SERVER_PROTOCOL']; var_dump($sp); echo "<br />\n"; ?> That code gives me: unicode(4) "Test" string(3) "GET" string(8) "HTTP/1.1" So the problem is that $_SERVER variables are binary strings? The HTTP specification says that all request methods are US-ASCII encoded (RFC 2616 section 5.1.1) so at least REQUEST_METHOD should be safe to convert to unicode. From the HTTP spec: CHAR = <any US-ASCII character (octets 0 - 127)> token = 1*<any CHAR except CTLs or separators> Method = "OPTIONS" ; Section 9.2 | "GET" ; Section 9.3 | "HEAD" ; Section 9.4 .... | extension-method extension-method = token