Oct 27, 2016

Enhance PHP source code by using heredoc

Heredoc helps our code easily mantainable. It is really useful for multi-line strings.
We will write our code like:

instead of using concatenation-dot syntax such as:

$db->query(
 "CREATE TABLE IF NOT EXISTS `users ` ( "
 . "`id`   int NOT NULL AUTO_INCREMENT, "
 . "`email`  varchar(255) COLLATE utf8_unicode_ci NOT NULL, "
 . "`usr`   varchar(255) COLLATE utf8_unicode_ci NOT NULL, "
 . "`pwd`   varchar(255) COLLATE utf8_unicode_ci NOT NULL, "
 . "PRIMARY KEY (`id`) "
 .");"
);
Related topic StackOverflow
Heredoc reference here

No comments:

Post a Comment