Skip to content

5.next: Fix TypeError: TableSchema::getConstraint#19090

Merged
markstory merged 2 commits into5.nextfrom
5.next-debug-schema
Nov 26, 2025
Merged

5.next: Fix TypeError: TableSchema::getConstraint#19090
markstory merged 2 commits into5.nextfrom
5.next-debug-schema

Conversation

@dereuromark
Copy link
Copy Markdown
Member

@dereuromark dereuromark commented Nov 26, 2025

TypeError: Cake\Database\Schema\TableSchema::getConstraint(): Argument #1 ($name) must be of type string, int given

Follow #19089

Annoying PHP behavior that keys of int even set as string revert to int.
So we have two options: A costly one (correct approach) to string cast on the returns:

     public function columns(): array
     {
-        return array_keys($this->_columns);
+        // Cast to string to handle numeric column names (PHP converts "1" to int 1 as array key)
+        return array_map('strval', array_keys($this->_columns));
     }
 
     /**
@@ -602,7 +603,8 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
      */
     public function indexes(): array
     {
-        return array_keys($this->_indexes);
+        // Cast to string to handle numeric index names (PHP converts "1" to int 1 as array key)
+        return array_map('strval', array_keys($this->_indexes));
     }
 
     /**
@@ -829,7 +831,8 @@ class TableSchema implements TableSchemaInterface, SqlGeneratorInterface
      */
     public function constraints(): array
     {
-        return array_keys($this->_constraints);
+        // Cast to string to handle numeric constraint names (PHP converts "1" to int 1 as array key)
+        return array_map('strval', array_keys($this->_constraints));
     }

or the simple approach in this PR.

@dereuromark dereuromark added this to the 5.3.0 milestone Nov 26, 2025
@dereuromark dereuromark changed the title 5.next debug schema 5.next: Fix TypeError: Cake\Database\Schema\TableSchema::getConstraint Nov 26, 2025
@dereuromark dereuromark changed the title 5.next: Fix TypeError: Cake\Database\Schema\TableSchema::getConstraint 5.next: Fix TypeError: TableSchema::getConstraint Nov 26, 2025
@dereuromark dereuromark requested a review from ADmad November 26, 2025 01:18
@markstory markstory merged commit 99c7f88 into 5.next Nov 26, 2025
15 checks passed
@markstory markstory deleted the 5.next-debug-schema branch November 26, 2025 15:12
@dereuromark
Copy link
Copy Markdown
Member Author

@markstory I thought this was part of 5.next as I had those in my test suite here.

but turns out also other projects running on 5.x (latest tag) have the same issue.

TypeError: Cake\Database\Schema\TableSchema::getConstraint(): Argument # 1 ($name) must be of type string, int given, called in /builds/.../vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureHelper.php on line 283

I think we need to backport this to current 5.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants