wfBaseConvert(): Avoid PHP warning when converting zero
authorKevin Israel <pleasestand@live.com>
Wed, 13 May 2015 07:36:43 +0000 (03:36 -0400)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 13 May 2015 15:52:49 +0000 (15:52 +0000)
The warning occurs when gmp_init() tries to convert the empty string
that came from ltrim(). This is causing tests to fail under HHVM 3.6.1.

Follows-up 5957856c46c3.

Bug: T98882
Change-Id: Ica86c91d7897db979e09d7cfc82fb3a20b95d4ce

includes/GlobalFunctions.php

index 6eaeb25..8b3b959 100644 (file)
@@ -3353,7 +3353,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
                // Removing leading zeros works around broken base detection code in
                // some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
                // <https://bugs.php.net/bug.php?id=55398>).
-               $result = gmp_strval( gmp_init( ltrim( $input, '0' ), $sourceBase ), $destBase );
+               $result = gmp_strval( gmp_init( ltrim( $input, '0' ) ?: '0', $sourceBase ), $destBase );
        } elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
                $decimal = '0';
                foreach ( str_split( strtolower( $input ) ) as $char ) {