lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP: In Support of Heredoc
One of the thing that puzzles me about many of the projects I've worked on is the seeming aversion to heredocs. The neat freak in me love heredocs. They make it so much easier to separate business logic and presentation logic. And that helps make code much cleaner.

I figured there were two reasons why they aren't used more extensively. 1) Programmers used to other languages don't know about them or feel comfortable with them. 2) There's a significant efficiency cost.

On the second point, I just discovered this: PHP string benchmark (php.net)

Cutting to the chase:

single quotes : 173ms
double quotes : 161ms
heredoc : 130ms


So I'm going to be a little more outspoken in my support of heredocs. Until I see some compelling evidence to the contrary, at least. Of course, it should be noted that this does not compare directly escaping PHP.

Here's my model for implementing heredocs in a web page framework: klenwell scriptframe

Labels: