Web Design Forum: An easy way to remember whether to 'echo'? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

An easy way to remember whether to 'echo'? Rate Topic: -----

#1 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 19 January 2012 - 09:08 PM

Hello,

I'm just learning php at the moment and probably have a stupidly easy question!!!

I'm getting confused on when 'echo' should be typed into a string or left out? Is there an easy way to remember when it needs to be included/left out?

Gary :)
0

#2 User is online   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 09:20 PM

If you want something to be output, you need to use echo, print, or in more severe (last output moments) exit or die
1

#3 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 19 January 2012 - 09:22 PM

View PostJay Gilford, on 19 January 2012 - 09:20 PM, said:

If you want something to be output, you need to use echo, print, or in more severe (last output moments) exit or die


Thanks.

I haven't got to exit or die yet but sure they'll crop up soon. :)
0

#4 User is online   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 January 2012 - 09:24 PM

They work in the same way really, with the exception that they terminate the code there and then
0

#5 User is online   Renaissance-Design 

  • Available for custom WordPress work
  • View blog
  • Group: Moderators
  • Posts: 3,595
  • Joined: 12-August 10
  • Reputation: 559
  • Gender:Male
  • Location:South Wales
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 19 January 2012 - 11:52 PM

As a rule of thumb you should write your functions to return a value rather than echoing unless their sole purpose is to take an input, format it and echo it to the screen. The perfect function performs one job. It's fine to pass the output of one function to another function to format and echo, or just echo the returned value of a function with:

echo my_function();

This post has been edited by Renaissance-Design: 19 January 2012 - 11:54 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users