From 685a8699fdc7cb76da76f36dba999fd20c43daa8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 21 Jun 2021 16:47:42 +0200 Subject: [PATCH] Embedded object ids are now explicitly casted to int 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. --- .../object/MessageEmbeddedObjectManager.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php index 1319449ab3..5f17806adf 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php @@ -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])) { -- 2.20.1