PHP as a template language

February 11th, 2010

It's been a while since I blogged, but I just ran into another zealot pointing me to NoSmarty.net when I mentioned templating.

I think I've said it before. The tool you use should depend on the job you're trying to do. So to say that Smarty is wrong just because it is, does not feel right.

I agree that in many cases PHP can be used as a template language just fine, but there are situations where a Smarty template (or any other templating engine) is just that more pleasant.

Here's a bit of template code that I encountered yesterday. Its use of php as a template language is hideous. Because it's a template for an xml message and because it needs to cope with systems with short open tags on and off, it looks like this:

 
<?php echo '<'; ?>?xml version="1.0" encoding="UTF-8"?>
<result processed="<?php echo $data["processed"]?"yes":"no"; ?>"
       <?php if (isset($data["orderid"])) { ?>orderId="<?php echo $data["orderid"]; ?>"<?php } ?> >
       <?php if (isset($data["error"])) { ?><error message="<?php echo $data["error"]; ?>" /><?php } ?>
</result>
 

Hideous!

Here's what it would look like in Smarty:

 
<?xml version="1.0" encoding="UTF-8"?>
<result processed="{if $data.processed}yes{else}no{/if}"
       {if $data.orderid} orderId="{$data.orderid}"{/if}>
       {if $data.error} <error message="{$data.error}" />{/if}
</result>
 

Yes, the first one is slightly more efficient, but the second one is actually readable for the average person.

Anybody claiming that <?php } ?> is 'just as convenient' as {/if} does not think clearly.

In my humble opinion, of course.

ZendCon 09 - Update and Slides

October 22nd, 2009

In my previous post I collected rumours about the opening keynote. Turns out none of them were right. The announcements were a beta of Zend Studio 7.1 and the beta release of Zend Server 5.0. The latter does get a step further in the enterprise direction with the addition of a Job Queue feature. I personally wasn't too impressed, Job Queues were already available in Zend Platform a year ago, and has since been overtaken by Gearman adoption. The new 'code trace' feature, which adds a kind of 'flight recorder' to PHP apps, looks very promising. Where past versions were already able to pinpoint where the problems were, this version will also give you a complete trace of every function call and parameter up to the problem. According to Andi Gutmans it performs fast enough to do that even on a production environment. I'm definitely going to check that out.

Today I had my own talk, "PHP and the Cloud". I had a godo 45 people in my session, which means that I owe the PHPBenelux usergroup a beer, since they showed up with 63 people for my Try-out last week. :-)

The slides for my session are on slideshare, or you can browse them directly here:

ZendCon 09 - The Rumours

October 20th, 2009

In about 15 minutes, Andi Gutmans is about to kick off ZendCon 09 with his opening keynote. Yesterday during the tutorial day and this morning over breakfast, I've been polling people to see what big announcements they expect this year. "Microsoft buys Zend" and other fun but improbable announcements aside, here's a selection of what people think might be announced today:

  • Zend Certification for PHP 5.3
  • Zend Framework 2.0
  • a Google AppEngine for PHP
  • Zend Studio Certification
  • Zend Server for OSX
  • Zend Server Enterprise Edition

If you follow me on Twitter, I'll probably mention any specific announcements there realtime.

Place the Photographer (a math/photography challenge)

October 8th, 2009

In a few months they will start to build the largest tower in The Netherlands (with 262 meters not a stunning accomplishment on a global scale, but impressive for our little otherwise mostly flat country). This will be very near my home, so I think it will be a nice project to take a snapshot every week of its progress, so that once it's finished I can create a little documentary of the construction.

I'm trying to find out the proper position to take this weekly picture, to ensure that the complete tower will fit in the picture precisely when it's finished, so that I don't have to move back after a while and can remain in the right spot for the duration of the project, and I'm close enough to not waste much pixels.

My camera has a certain viewport, so plain old Pythagoras won't be sufficient; so I'm trying to figure out what the best position will be, and how I can determine this using nothing more than math, some experimentation and educated guesswork. I'm relatively lazy, so it has to be a simple practical method that doesn't take ages or enormous amounts of effort. Also, it has to be a verifiable method so I don't end up moving the position halfway through the project; they're only going to build this tower once.

The position of the tower will be:


View Larger Map

Ideas? I'll throw in a signed copy of my enterprise php book for the most creative or pragmatic approach, or an amazon gift certificate for those not into PHP.

Bonuspoints if you point out the spot on the map, taking into account buildings or other structures

More details (if relevant):

  • The camera will be this Canon Ixus 95
  • I am able to use a tripod
  • Most roads near the construction site are at the same level as the start of the tower (to my knowledge, anyway)
  • The A2 highway north of the tower has elevated soundproof walls, so anything on the other side of the A2 is not an option.
  • Details on the tower are here.

Have fun!

Update: I might actually use my Canon 450D for this project. Based on this blogpost, the construction company has contacted me that they are interested in the project and would like to cooperate.