#13399 closed defect (bug) (invalid)
Code Improvement: Consider print instead of echo
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
There is a lot of echo
in WP sourcecode. Instead of calling a function it is better use the intended language construct for doing output: print
Learn about print:
http://www.php.net/manual/en/function.print.php
Compare to understand the differences to echo:
http://www.php.net/manual/en/function.echo.php
Normally, echo calls should be easy to replace with print.
Change History (5)
#2
in reply to:
↑ description
@
15 years ago
Replying to hakre:
Instead of calling a function it is better use the intended language construct for doing output: print
Could you clarify your point? According to the PHP doc at your echo
link:
echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo() (unlike some other language constructs) does not behave like a function
Also, I've read in several places over the years that echo
is faster than print
, although I haven't tested it myself. echo
does seem to be the most common choice across a wide variety of PHP applications.
#3
follow-up:
↓ 4
@
15 years ago
- Milestone 3.1 deleted
- Resolution set to invalid
- Status changed from new to closed
- Version 3.0 deleted
My fault, you're absolutely right. This went through my fingers, I thought I had checked for that.
Therefore #13395 / http://core.trac.wordpress.org/changeset/14647#file13 Change is pretty useless to replace echo with a function call containing echo only. But that only as sidenote here.
#4
in reply to:
↑ 3
@
15 years ago
Replying to hakre:
Therefore #13395 / http://core.trac.wordpress.org/changeset/14647#file13 Change is pretty useless to replace echo with a function call containing echo only. But that only as sidenote here.
It's a shortcut for the however many thousand times we're translating strings. Not unlike __
instead of translate
, _x
instead of translate_with_context
,_e
instead of echo translate()
, _n
instead of ngettext
, _nx
instead of ngettext_with_context
, etc.
#5
@
15 years ago
Naturally I saw that, but that's not the point I wanted to make.
If it's for the shortcut (by typing, no processing wise), I've made another suggestion in the other ticket.
The problem I have with that (and what I wanted to say with my "pretty useless" comment) is that the introduction of new functions that do not provide new functionality are just useless.
Next to this that implementation has some overhead.
I can understand that you do not want to type much, but cryptic function names must not be seen as very helpful either.
But there are pros as well: Hackers, that now the project can save themselves some keys to type, and it can compress the code-size:
echo _x
(7 bytes)
_ex
(3 bytes), that's a 233% saving.
Let me know if you like to see a patch for this.
Somehow related: #13395