The WordPress Anthology: Why open a PHP tag before Function close on pages 86,89

Note: I could’ve sworn a long time ago, there was forums dedicated to the specific books so questions could be asked but now I am not sure if it was my imagination. If this post belongs in a different category, please move and my apologies for the confusion.

  1. On Page 86 and 89, before the function is closed it places a Opening PHP tag, but doesn’t explain why you put an opening PHP code before closing a function.

Like 86 has the following:

<input size="45" name="conference_speaker_location"
value="<?php echo $conference_speraker_location; ?>" /></p>


I don’t understand the purpose of the opening PHP tag before the closing curly brace. Not all functions in the book have that opening PHP tag. Which is confusing me on when and where it should be used.

If anyone can explain this to me, that would really help me out a lot.

Thank you in advance!

Yes, there was a “book” forum but it was removed along with a few others during the recent restructuring.

On page 85, there is

$conference_speaker_location = $custom['conference_speaker_location'][0];

This is known as going “in-and-out”. Rather than have PHP echo or print the HTML some developers choose to go “out” of PHP, but since it’s a function you need to go back “in” before you have more code closing the function. Things can get messy looking and the technique can spur some hot debate as to how things should be done, but that’s it.

Thanks for the reply :). I am still quite not sure whether or not or when I should use it? Is there any benefit or times I shouldn’t use it?

I think it’s mostly a matter of personal style and preference and if it’s for your own use you can pretty much do what you like.

Various arguments include:
Should code be mixed with mark-up at all? eg. MVC
What is the more efficient use of resources? i.e. memory and processing
Code readability
Code maintenance

and more I can’t think of ATM

In this case, because it’s WordPress a lot of the code will need to conform to WordPress standards to fit in, but there’s still plenty of leeway.

IMHO as long as you can read it easily, it makes sense to you, and it works, then it’s probably good enough.

You’ll know when you need to change whatever approach you take when you start having problems. I find that as long as it’s only a few it isn’t a problem or likely to become one. But if it’s a lot I prefer HEREDOC syntax instead.