Yesterday, in IRC I saw lots of frustration and gnashing of teeth over PHP and its handling of _toString() errors.
This made me feel a little guilty because, under the 'Probably bug' section of my lint tool I had seen pile of lint error in this regard and done nothing ... so here goes..
Method __toString is not implemented for the following objects.
\Drupal\Core\Database\Query\SelectInterface ( x4 )
#2344831: Document behavior of Drupal/Core/Database/Query/SelectInterface::__toString()
\Drupal\Core\Url
#2345089: lint error _toString() is not implemented in batch.inc
\Drupal\editor\EditorXssFilter\Standard
#2344823: Drupal\Tests\editor\Unit\EditorXssFilter\StandardTest has trivial lint error
No drama they seem simple to fix.
I have selected the database system as the component only because most of the errors come from there.
here is an example of the code which triggers errors.
Definition of Drupal\Core\Database\Driver\sqlite\Insert
the code in error is that $this->formQuery is converted into a string without an explicit definition in the \Drupal\Core\Database\Query\SelectInterface interface
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$comments = $this->connection->makeComment($this->comments);
// Produce as many generic placeholders as necessary.
$placeholders = array_fill(0, count($this->insertFields), '?');
// If we're selecting from a SelectQuery, finish building the query and
// pass it back, as any remaining options are irrelevant.
if (!empty($this->fromQuery)) {
$insert_fields_string = $this->insertFields ? ' (' . implode(', ', $this->insertFields) . ') ' : ' ';
return $comments . 'INSERT INTO {' . $this->table . '}' . $insert_fields_string . $this->fromQuery; <-- triggers error
}
return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';
}
Comments
Comment #1
martin107 CreditAttribution: martin107 commentedComment #2
martin107 CreditAttribution: martin107 commentedThe lint error regarding \Drupal\editor\EditorXssFilter\Standard is trivial to fix.
Comment #3
martin107 CreditAttribution: martin107 commentedIn #2 I forgot to link .. sorry
Comment #4
martin107 CreditAttribution: martin107 commentedThe \Drupal\Core\Database\Query\SelectInterface issue is a API change / beta-target which is maybe too late to slip in :(
Comment #5
martin107 CreditAttribution: martin107 commentedupdating summary with url/batch.inc fix.
Comment #6
martin107 CreditAttribution: martin107 commentedToday the last sub issue was fixed. :)