Last modified: 2007-02-02 18:27:25 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 8187 - fix_magic_quotes in includes/WebRequest.php generates warnings most of the time
fix_magic_quotes in includes/WebRequest.php generates warnings most of the time
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
All All
: Low minor (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
  Show dependency treegraph
Reported: 2006-12-07 20:40 UTC by nickk2
Modified: 2007-02-02 18:27 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description nickk2 2006-12-07 20:40:52 UTC
At line 66, the function fix_magic_quotes generates warnings at foreach when
given an empty array. Fix - Add a check for empty arrays before foreach:

function &fix_magic_quotes( &$arr ) {
  if (!empty($arr)) {
      foreach( $arr as $key => $val ) {
Comment 1 Brion Vibber 2006-12-08 00:07:46 UTC
The current code would not produce a warning for an empty array.

It would however produce a warning if you pass it something *that is not an array*.

Can you clarify exactly under what conditions you
see a warning, and what the warning is?
Comment 2 nickk2 2006-12-08 16:07:30 UTC
I doubt it's going to get something that's not an array. Currently it's only
being used in one place - in the function checkMagicQuotes in WebRequest.php,
which checks a bunch of arrays, some of which can be empty at any given time.

The warning is "PHP Warning: Invalid argument supplied for foreach()", which was
happening when it was being given an empty array.

This is with PHP 5 so maybe the behavior has changed since version 4.
Comment 3 nickk2 2006-12-08 17:03:49 UTC
I've checked this function a bit more, and you're right about foreach being able
to take empty arrays. It seems that the function is sometimes getting values
that are not arrays which is causing the problem.

It seems that sometimes NULLs are being given to fix_magic_quotes instead of
arrays. It might have something to do with APC because I'm getting some really
strange behavior. I put in a bunch of statements to check the types of each
array that was being passed to the function sort of like:

(in checkMagicQuotes):
   if (!is_array($_COOKIE)) { .... }
   if (!is_array($_ENV)) { .... }

then the warnings go away.

Actually, I suspected this might have something to do with the PHP setting
auto_globals_jit. Seems this is a bug with APC:

Setting auto_globals_jit to off seems to solve the problem. I'm using the latest
version of APC, so I don't know why this is a problem.
Comment 4 nickk2 2006-12-08 17:07:32 UTC
Maybe a check for an array should be added to the fix_magic_quotes function anyway?

Something like:

function &fix_magic_quotes( &$arr ) {
if (is_array($arr)) {
foreach( $arr as $key => $val ) {
Comment 5 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-02-02 17:08:47 UTC
I wouldn't be comfortable doing that until I know why it's not passing an array.  It could be the 
symptom of some other problem.
Comment 6 Brion Vibber 2007-02-02 18:27:25 UTC
Sounds like an upstream bug; if it's that bad (eg, COMPLETELY BROKEN) there's
not much we can do about it. Get it fixed and install a fixed version of the PHP

Note You need to log in before you can comment on or make changes to this bug.