r49428 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49427‎ | r49428 | r49429 >
Date:17:38, 12 April 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Fix warning in PHP 5.1 when feeding Title objects to wfArrayToCGI(). Also enforce consistent style
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1230,18 +1230,18 @@
12311231 if ( '' != $cgi ) {
12321232 $cgi .= '&';
12331233 }
1234 - if(is_array($value))
1235 - {
 1234+ if ( is_array( $value ) ) {
12361235 $firstTime = true;
1237 - foreach($value as $v)
1238 - {
1239 - $cgi .= ($firstTime ? '' : '&') .
 1236+ foreach ( $value as $v ) {
 1237+ $cgi .= ( $firstTime ? '' : '&') .
12401238 urlencode( $key . '[]' ) . '=' .
12411239 urlencode( $v );
12421240 $firstTime = false;
12431241 }
1244 - }
1245 - else
 1242+ } else {
 1243+ if ( is_object( $value ) ) {
 1244+ $value = $value->__toString();
 1245+ }
12461246 $cgi .= urlencode( $key ) . '=' .
12471247 urlencode( $value );
12481248 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r49429Fix up r49428: add missing bracecatrope18:15, 12 April 2009

Comments

#Comment by Nikerabbit (talk | contribs)   07:18, 13 April 2009

Shouldn't the caller causing the warning be fixed instead of silently ignoring any possible bugs?

#Comment by Catrope (talk | contribs)   10:43, 13 April 2009

This is really a PHP bug, because objects should be juggled to strings automatically, but aren't in 5.1. You're right that it's maybe a little weird to pass objects to this function, but it's legitimate IMO.

Status & tagging log