Re: Usage of class constants inside strings and heredocs [message #170515 is a reply to message #170514] |
Fri, 05 November 2010 13:01 |
Matthew Leonhardt
Messages: 9 Registered: November 2010
Karma:
|
Junior Member |
|
|
"Giuseppe Sacco" <eppesuig(at)gmail(dot)com> wrote in message
news:e35bdb56-6101-478c-891b-0facb4ebc0aa(at)g13g2000yqj(dot)googlegroups(dot)com...
> oops, I forgot to add the part about class constants in strings...
> in all derived classes, I have special method for common operations on
> specific tables. As an example, delete records:
>
> class Comunicazioni extends Table {
> // declare all field as class constants
> // ...
> public function CreaDeleteStatemnt() {
> return "DELETE FROM {$this->nometabella}\nWHERE
> ".Comunicazioni::DB_COD_ANAG."=\$1 AND
> ".Comunicazioni::DB_COD_ORIGINALE."=\$2";
> }
> } // end class Comunicazioni
>
> This is where I would like to use heredoc: I am in a derived class, so
> I do not need reflection, and I need to create a prepared statement,
> so I use placeholders instead of real values.
I don't see how any of this is relevant...
public function CreaDeleteStatemnt()
{
$delSql =<<<SQL
DELETE FROM %s
WHERE %s=\$1 AND %s=\$2
SQL;
return sprintf($delSql, $this->nometabella, Comunicazioni::DB_COD_ANAG,
Comunicazioni::DB_COD_ORIGINALE);
}
Does Alvero's (very elegant) suggestion of mixing heredoc with sprintf() not
fulfill your requirements for some reason?
|
|
|