Fix unexpected return type of User::idFromName()
authorThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Mon, 3 Dec 2018 13:33:48 +0000 (14:33 +0100)
committerThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Mon, 3 Dec 2018 13:33:48 +0000 (14:33 +0100)
The user_id is an unsigned integer in the database. But not all database
abstractions we use are guaranteed to return integer values as PHP
integers. Sometimes it's a string and needs an integer cast first.

Want proof? Search for usages of this method. Almost all add an (int)
cast. This is weird and should not be necessary.

Change-Id: If1d706f73350fca5b3a0f1e0de59e4518162445b

includes/user/User.php

index 0bea7e3..bf84833 100644 (file)
@@ -935,7 +935,7 @@ class User implements IDBAccessObject, UserIdentity {
                if ( $s === false ) {
                        $result = null;
                } else {
-                       $result = $s->user_id;
+                       $result = (int)$s->user_id;
                }
 
                self::$idCacheByName[$name] = $result;