Jump to content

Recommended Posts

Posted

I'm curious what the general consensus is about using php "short tags" (e.g. "<?=" instead of "<?php echo") in processwire modules. I know that this presents issues for some people because the feature is not enabled by default on some servers, but since PW requires php 5.3 and maybe caters to a more technically-inclined audience, I'm wondering what the standard practice is.

I searched through the codebase of PW core itself, and I only see "<?php echo", so I am guessing it's still best to stick to that. But maybe the module authors don't stick to that as much?

Also when answering peoples' questions in the forums, do you try to stick to the full "<?php echo" instead of "<?=" -- because then you avoid one possible error that is unrelated to whatever they are asking the question about? Or does pretty much everyone have the short tags enabled these days so it's not much of an issue?

Thanks!

   -Jordan

Posted

Can't speak for everyone here, but I won't be using them anytime soon. Short opening tags depend on a PHP settings in all PHP versions, so they're never guaranteed to work. While short echo (<?= $whatever ?>) is generally speaking more acceptable -- after all it's always enabled in PHP 5.4+ -- it might not work in all setups using earlier PHP versions.

By the way, the accepted answer to this Programmers Stack Exchange question has a simple chart about using the short echo tag. Since ProcessWire officially supports PHP 5.3.8, I would suggest avoiding them in your modules, even if just to be consistent with the core system itself.

  • Like 3
Posted

Not a direct response to your question but I have never liked the PHP short tags (just a matter of preference). Even on personal sites where I am sure short  tags feature is enabled, I never use them.

I don't think there is a general consensus about their use (or not) in modules but I would urge all module developers to stay clear of them just to ensure compatibility..

  • Like 3
Posted

Thanks guys, I will avoid it for PW modules. I do like using them myself (the markup is more aesthetically pleasing to me when I can do <p><?=$something?></p> as opposed to <p><?php echo $something; ?></p>), but if enabling the short tags isn't part of the PW installation requirements, then I don't want to risk it breaking on anyone else's servers.

Posted

I like the short tags and use them in my sites, but agree with previous answers that they shouldn't be used in modules.

Posted

I would never recommend the use of short tags in any PHP documentation (when it's not about short tags :-)). It's not unlikely that someone following a doc is a newby on PHP. Letting them think about short tags obscures the main purpose of the doc, leaving less room in his mind to digest the actual purpose of the documentation.

And of course all the above said.

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...