Jump to content



Photo

Heredoc Best Practices

heredoc

  • Please log in to reply
2 replies to this topic

#1 Necuima

Necuima

    Advanced Member

  • Members
  • PipPipPip
  • 255 posts
  • LocationSunshine Coast, Queensland, Australia

Posted 30 September 2016 - 12:23 AM

Hi Larry,

 

The reference is from page 32 of the book - I think I've got the first edition - sorry if I've posted this in the wrong spot.

 

I am seeking advice on heredoc best practices.  Here's an example that I've been experimenting with:

 

The scenario is a program to edit the information about an item whose details have been retrieved from a database via a standard MySQL select.  The data get loaded into an HTML form with the variables from the database interpolated into the form.

 

There appear to be two approaches:  1) to have most of the form HTML with the database data added via <?php echo $var; ?> with any number of these echos.  Or 2) heredoc echo the whole form thus avoiding the need to have all the PHP insertions.

 

I have tried both approaches and they both work fine.  The second approach looks 'cleaner' to me, but I'm wondering if it's "bad coding form"?

 

Thanks in anticipation for your thoughts or any other forum member's thoughts.

 

Cheers.

 

P.S., the updated from data get processed via PHP Redux.


  • 0

#2 Necuima

Necuima

    Advanced Member

  • Members
  • PipPipPip
  • 255 posts
  • LocationSunshine Coast, Queensland, Australia

Posted 30 September 2016 - 2:37 AM

That should be "updated form data". Sorry for the typo.


  • 0

#3 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4785 posts
  • LocationState College, PA (USA)

Posted 30 September 2016 - 1:49 PM

It's definitely a matter of personal preference and not bad form either way. I tend not to use heredoc mostly because I don't remember to use it! I'd go with the approach you prefer. 


  • 0