Cast `$length` to an actual `int` in TLengthDatabaseTableColumn::length()
authormutec <mysterycode@mysterycode.de>
Sun, 28 Nov 2021 10:49:39 +0000 (11:49 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 7 Dec 2021 14:02:46 +0000 (15:02 +0100)
When the object is being initialized from the existing structure in the
database, the length will be passed as a string and was previously stored as-is
within the object.

This violates the existing PHPDoc type declaration and breaks consumers that
use a strict comparison (`===`) to check the length, notably
`YearDatabaseTableColumn`.

Fix this by casting the passed parameter to an actual `int`. This should be
adjusted to a proper parameter type in a future version.

Resolves #4594

[Tim: Adjusted commit message]

wcfsetup/install/files/lib/system/database/table/column/TLengthDatabaseTableColumn.class.php

index d6b6655f2ed790814b9f88dd99062ba1fac2e5aa..4d36840c3bde396a8e4ac3dc49452a63bfd145ca 100644 (file)
@@ -55,6 +55,7 @@ trait TLengthDatabaseTableColumn {
         */
        public function length($length) {
                if ($length !== null) {
+                       $length = (int) $length;
                        $this->validateLength($length);
                }