Home » Internet » Web Development

How PHP Developers Differentiate Between Print And Echo

Jul 11, 2008
Few other web development languages have done as much for web developers as PHP has. And in learning all the complexities of the language, web developers will be able to better become higher paid, more satisfied, and better prepared to make the next best web application. But taking baby steps in getting there is important: and the finer things such as knowing the difference between Echo and Print become clear.

Two commands are used to output text to the screen: Print and Echo. But since both do the same thing, why would there be two different commands? The answer, interestingly enough, eludes even some PHP experts.

As it turns out, Echo is actually a language construct that doesn't return a value, in which Print does. This simple fact means that Print can be used in some instances where Echo can't, although developers will probably never run into such a situation. In fact, many PHP developers stick with Echo their entire career and will never see a problem.

Speed is a major concern in web applications. This holds true with the Print and Echo commands since it is logical to think that Print would cost more in resources to operate. This logic is actually true, although the differences in performance are so small that it isn't even worth choosing one construct over the other solely based on performance.

When a PHP developer looks around at examples and scripts from others in the community, they will see that Echo is used much more often. This isn't because of speed, as previously discussed, but because many think it easier to type and the keyword command is more appealing in design. The success of Echo has been compounded after many publishers make books and online resources that sport the term.

As a last note of worthiness, it should be made clear that if speed is an issue, more emphasis should be put on how the two commands are used. Repeatedly using either command where a programmer could simply concatenate a string or value together will waste system performance- and on a much more noticeable scale that the difference between returning a value or not. Thus, this subject should be addressed if anything in regards to speed.

Closing Comments

Echo and Print will continue to confuse new developers that are learning PHP- this will never change. But as time wears on, it is more likely that the emphasis is going to be put on Echo. Already, there is a large emphasis place on using Echo simply because instructional resources do so. While Print may not be phased out, it will always be in the background for those who remember the "good old days" when the Print command was all a programmer had.
About the Author
Learn more on PHP Print and PHP Echo.
Rating:
Please Rate:
(Average: Not rated)
Views: 169
Print Email Report Share
Article Categories