The problem is that I have a SQL-builder which uses exceptions from __toString() if some data is missing (eg. a FROM part).
I use __toString() because it makes it a lot easier to concatenate strings with objects:
Code: Select all
$string = implode(', ', $list);
$string = ‘’;
?foreach($list as $element)?
{?
if($element instanceof Some_class)?
{?
$string .= $element->getString();
? }?
else
? {
? $string .= $element;
? }?
}
// Instead of
$string = implode('', $list);So what I've figured so far is that I probably need to embed the error in the generated string, and then search for the error string in the generated SQL before I send it to the database:
Code: Select all
function getSQL()
{
$sql = $this->__toString();
self::detectError($sql);
// db interaction...
}And if you know any other way of throwing exceptions from code which is run in __toString(), please tell.