Skip to main content

Maximum failure: PHP 6 deprecates short tags

I just discovered that PHP 6 is officially deprecating short tags. I'm sorry, but short tags are incredibly useful. They should be turned on for every server. They simplify coding dynamic actions within HTML. Plus, you get the added bonus of using:

<?=$x?>

Which is short for:

<?php echo $x; ?>

Compare: 7 characters vs. 17 characters. The latter is over twice the length, quite unreadable, and, from personal experience with large code bases, unmaintainable! Typing 'php echo' in every time I want to execute/display data that is hosted within the PHP engine is ridiculous. This is a step backwards going in the wrong direction.

The lame excuse for removing short tags is XML. PHP is for HTML, not XML.

I write PHP code quite regularly. Prior to PHP 5, PHP stunk. PHP 5 really changed my view of scripting languages. PHP 6 is going to ruin that view as we will return, once again, to the dark ages of software development. What really gets me is that someone made a decent recommendation and the PHP development team scoffed at the idea and one person even had the gall to suggest that syntax highlighting is all that is needed - let me point out that blind PHP programmers probably don't want to hear JAWS attempting to speak '<?php echo' over and over again and syntax highlighting is a useless recommendation to a blind programmer. I can imagine a small army of blind PHP programmers beating up the PHP developers (especially the one developer who made the recommendation to use syntax highlighting) while blaring an audio recording of JAWS speaking '<?php echo' over and over.

XML seems to be the pervasive reason. I personally dislike XML and wish it would go away (I also wish Ruby, Perl, and Python would go away too - all three are equally terrible languages - and, yes, I've used them all). I've used XML enough to know that it is a terrible storage mechanism for any data. JSON is better but still not perfect. The PHP serialize() function gets even closer but is a language-specific solution. XML is hereby a lame excuse for not coming up with an alternate short tag strategy.

If XML is sooo important, then simply recognize the sequence of characters '<?xml ' and ignore it. It is already invalid PHP code, so fix the problem transparently. Oh the horror! Three lines of code at most is all that is needed. This whole issue is over a data storage format that isn't commonly output by PHP, is a terrible storage format to begin with, and is over the two starting characters at the very beginning of the storage format. Most people DO NOT EVEN USE XML in the first place! Requiring '<?php echo ' every time output is needed from within the PHP engine in HTML is a surefire way to tick people off. Especially when they learn that the reasoning is the two measly characters at the start of a XML document.

Good grief. I can't believe I'm having to tell the PHP developers how to write software. I'm now going to start tagging posts with "maximum failure" for areas where programmers have failed spectacularly to see the simple solution to a problem. End-users (PHP programmers) want short tags in PHP, the PHP developers see a singlular issue with XML and proceed to blow the whole thing out of proportion, and there is an easy fix (see previous paragraph) that allows both camps to be happy - it is as simple as that.

I'm hoping that as soon as PHP 6 comes out of its internal development cycle and becomes the official release, there will be a significant (read: massive) backlash in the short tag department. In other words, I'm hoping the PHP developers will be forced to add short tags back in and undeprecate them. The only reason there hasn't been a huge backlash already is because: No one knows they are already deprecated, deprecated functionality is rarely enforced, and people are too lazy to rewrite code that works just fine. So, I have one question:

Can the PHP internal developers mailing list handle a million programmers dropping by and asking the same question over and over and over and over and over and over again?

Edit: To date I've rejected all comments to this post. People are attacking me personally and completely ignoring both the purpose of this post and this blog as a whole. This is my rant blog - a place to let off steam - if you don't like it, then don't comment and simply leave. Sheesh.

Comments

  1. Amen brother. The php core team is smoking crack. I use <?= all the time and think <?php echo is a waste of time and very ugly... Maybe its time to jump ship and start developing in Ruby and Rails...?

    ReplyDelete
  2. PHP, at the moment, is the only good web language. I agree with you about the devs smoking crack. My experience with Ruby (and Rails) is that, without Rails, Ruby is worthless. In other words, the framework makes Ruby rather than Ruby making the framework. PHP is simple and stands on its own, which is why millions use it. Removing simplicity goes against the very foundation upon which PHP is built. PHP 5 really made the language solid - it took the best of the best, built on it with tons of additional functionality, and yet maintained the things that make it simple to use such as short tags (it also introduced serious Zend core performance improvements).

    ReplyDelete
  3. I don't know if this is still up to date, but according to them, they concluded there won't be any <?php =

    Good news for you is, they decided to keep php short tags :-)

    ReplyDelete
  4. Cornelius - At the top of the page of the meeting notes, it says "Paris, November 11th and 12th, 2005". Visiting his root directory (removing the 'meeting-notes.html' from the URL) shows a list of PHP 4.4.x builds. You got my hopes up though. The links in this blog entry are from April 2009.

    ReplyDelete
  5. Why they don't just check for spaces directly after <? is beyond me--if it finds '<?x' it knows it's xml, if it finds '<? ' it knows it's php. Then just add an additional rule so that '<?=' translates to '<?php echo' and everything works just fine. Personally I think it's just a case of the PHP developers getting sick of non-programmers going to them for debugging help when their short-code enabled code they downloaded from somewhere else doesn't work on their server. >.>

    ReplyDelete
  6. Where did you read that short tags are being removed from PHP 6, was it an "official" source? (Also what date was the source of that info published, most of the info about for php 6 seems to be from around 2002)?

    ReplyDelete
  7. Stephen - Excellent observation. That would be a great solution. <?php is <?php, <?= is <?php echo, <?[space] = <?php, and then anything else is ignored (XML or otherwise). Then there wouldn't need to be a short tag declaration in the INI file - it would merge both worlds quite nicely. You are my hero today for seeing a solution I didn't see.

    Lee - Yes. One of the two links in the blog post is dated 'Tue, 14 Apr 2009' and is a public archived copy of the e-mail exchange on the official PHP 'internals' (developers) mailing list that prompted this post. You should read it as it provides some insight into how lost the PHP development team is getting. This sort of thing tends to happen to a product that has reached a certain level of perfection.

    ReplyDelete
  8. While I do agree that ignoring <?xml would be the best solution, XML is very much useful. HTML doesn't support namespaces. Creating elements in your own namespace allows you to do more with styling and scripting.

    ReplyDelete
  9. potatisi - Google (you know - that large company that makes billions of dollars annually) would disagree with you here. They have switched entirely over to JSON as their preferred data exchange format. And I have to agree with them. Take a serious look at JSON. JSON has that finesse and elegance that XML is missing. The ONLY thing XML is good for is RSS/ATOM feeds - and only because those things are standardized on XML. I'd much rather they were standardized on JSON.

    ReplyDelete
  10. http://marc.info/?l=php-internals&m=126832992915664&w=2

    You might look at more recent topics. Short tags will not be depreciated. Their also talking about unhooking <?= from the shorttags flag (not final, it's just talk), so I don't think we'll be seeing that go away anytime soon.

    ReplyDelete
  11. There's even more recent discussion in PHP-DEV on this. I'm on the mailing list so I track stuff like this. Someone just submitted a patch for <?= to be recognized regardless of short tag settings and the devs are debating whether or not to add it to the trunk.

    ReplyDelete
  12. Quite a few months past the last post, but did anyone realize phone application development uses xml? I agree for data storage slower than molasses but for a custom layout in a phone app maybe not so bad.

    ReplyDelete
  13. I discovered this issue by accident as a client has host gator account with short tags turned off by default. I realize this is a bit of necromancy pulling this thread up but sometimes we have to get dirt under our fingernails.

    I'd strongly support disconnecting <?= from short tags, always seemed an unholy union. As someone that's used php for html, xml, javascript images -- you name it, the basic point of the devs makes a little sense, however, the idea of deprecating it strikes me as a bit of laziness on the part of the devs. I'm torn over using <?= in new code though, and will be googling around some more trying to see what the state is.

    ReplyDelete
  14. "Since PHP 5.4.0, <?= is always available. "

    ReplyDelete
  15. @jimbob - Do you know WHY your statement is true? Because I raised a huge stink about short tags over on the PHP developers mailing list and it was the compromise that the developers came up with.

    ReplyDelete

Post a Comment