Embedded object ids are now explicitly casted to int
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jun 2021 14:47:42 +0000 (16:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jun 2021 14:47:42 +0000 (16:47 +0200)
https://wiki.php.net/rfc/string_to_number_comparison changed the behavior of PHP when comparing strings to numbers.

`123 == "123foo"` is true in PHP <8.0, but false starting with PHP 8.0.

wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php

index 1319449ab354c4d3e49e74e53a8706ec759ad116..5f17806adfe5b6b2e704af92fba48aa0a2057f70 100644 (file)
@@ -382,6 +382,17 @@ class MessageEmbeddedObjectManager extends SingletonFactory
      */
     public function getObject($embeddedObjectType, $objectID)
     {
+        // `$objectID` might contain non integer values containing a comment, such
+        // as `123#This is a comment`. PHP <8.0 would silently truncate the value
+        // similar to what `intval()` does, making the below comparison work.
+        //
+        // However, in PHP 8.0 it was decided that this behavior is intransparent
+        // and somewhat violates the implicit casting rules, such a comparison
+        // now yields `false` where it was previously true.
+        //
+        // See https://wiki.php.net/rfc/string_to_number_comparison
+        $objectID = \intval($objectID);
+
         $embeddedObjectTypeID = ObjectTypeCache::getInstance()
             ->getObjectTypeIDByName('com.woltlab.wcf.message.embeddedObject', $embeddedObjectType);
         if (!empty($this->messageEmbeddedObjects[$this->activeMessageObjectTypeID][$this->activeMessageID][$embeddedObjectTypeID])) {