FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Usage of class constants inside strings and heredocs
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Usage of class constants inside strings and heredocs [message #170515 is a reply to message #170514] Fri, 05 November 2010 13:01 Go to previous message
Matthew Leonhardt is currently offline  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?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Free Web Space for our Experiments
Next Topic: There is some framework/tool to generate PHP code
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 03:03:45 GMT 2024

Total time taken to generate the page: 0.03778 seconds