Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8 string offset warnings in getColumnName and addIndex #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions lib/Doctrine/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,21 +879,19 @@ public function addCheckConstraint($definition, $name)
*/
public function addIndex($index, array $definition)
{
if (isset($definition['fields'])) {
foreach ((array) $definition['fields'] as $key => $field) {
if (is_numeric($key)) {
$definition['fields'][$key] = $this->getColumnName($field);
} else {
$columnName = $this->getColumnName($key);

unset($definition['fields'][$key]);

$definition['fields'][$columnName] = $field;
}
}
if (!isset($definition['fields']) || !is_array($definition['fields'])) {
$definition['fields'] = [];
}
foreach ((array)$definition['fields'] as $key => $field) {
if (is_numeric($key)) {
$definition['fields'][$key] = $this->getColumnName($field);
} else {
$columnName = $this->getColumnName($key);
unset($definition['fields'][$key]);
$definition['fields'][$columnName] = $field;
}

$this->_options['indexes'][$index] = $definition;
}
$this->_options['indexes'][$index] = $definition;
}

/**
Expand Down Expand Up @@ -1171,10 +1169,11 @@ public function processOrderBy($alias, $orderBy, $columnNames = false)
*/
public function getColumnName($fieldName)
{
// FIX ME: This is being used in places where an array is passed, but it should not be an array
// For example in places where Doctrine should support composite foreign/primary keys
$fieldName = is_array($fieldName) ? $fieldName[0]:$fieldName;

if (is_array($fieldName) && !empty($fieldName)) {
$fieldName = $fieldName[0];
} else {
$fieldName = is_array($fieldName) ? null : $fieldName;
}
if (isset($this->_columnNames[$fieldName])) {
return $this->_columnNames[$fieldName];
}
Expand Down