Jan 10
Heredoc, Sit! Stay!
posted by: Player0 in php on 01 10th, 2009 | | No Comments »

I’m still using Symfony and I find some of it’s philosophy disagreable.  But one of the things that urks me the most is it’s claim that alternate PHP templating syntax, such as if…endif, is a good idea.

Take listing 4-5 for example:

<p>Hello, world!</p>
<?php if ($test): ?>
<p><?php echo time(); ?></p>
<?php endif; ?>

For real? Do you really want to treat every problem the same? Do you really think this is readable?  I take issue with the thought that you always have to nest PHP inside of HTML.  Sometimes it makes sense to do it the other way around.  I would do it this way:

$time = $test ? time() : ”;

echo <<<TEMPLATE
<p>Hello, world</p>

In this simple example the benefit may not be completely obvious. But this shows a very clear separation of logic and template which most architects seem to ignore, even if you’re using Symfony.

The trick to it is to think of any PHP-rich output as a template and use the heredoc to wrap that output.  You can only include variables and object members in it.  It’s an extra step to store all the local variables needed for the heredoc but the added separation and clarity of this code is far more important.

The html p tag is an interesting choice here.  My code doesn’t do exactly the same thing as the above code because I’m always rendering the second block element.  But that’s really okay!  Leave it there and make sure your CSS is smart enough to not render silly whitespace around empty p tags.

In a more complicated example, $time itself might actually be a whole separate template which you can then tie in to another template and so on and so forth.  This format also lends itself beautifully to object oriented display.

public function output() {
echo <<<TEMPLATE

It’s just a small example but I’ve used it in many application and it really simplifies those times where you need to embed PHP in a template.  Don’t use smarty.  Don’t roll your own templating system.  Just use what PHP gives you.

And never use more than one set of <?php ?> tags to do a PHP conditional I’m begging you.  And on that subject, endif, endforeach, endwhile is ugly.  If we can’t tell what kind of brace you’re closing without you telling us than YOU’RE DOING IT WRONG.

Opinions will vary wildly.  But do give heredoc a chance.  It’s a wildly underrated feature and it really makes dealing with output much easier.

As for Symfony itself well… I’m still making the determination about just how much I like or dislike it as a whole.  I do kind of like Propel but I’m not 100% sure what Symfony itself brings to the table outside of that.  It enforces an MVC model but big whoop.  Any decent PHP programmer would build something in that pattern anyway.  YAML config is nice and all but the implementation is sloppy and it seems to add a lot of function overhead.  Caching the PHP file structure is nice though.  Propel can save a little time but it certainly doesn’t do all the things I’d like it to do.  And I’ve never agreed with abstracting the DB layer from the controller layer unless you ABSOLUTELY need to support multiple database products.  And that’s not common.

Symfony manages to abstract enough of the baseline PHP to make it a learning curve but I can only imagine how much performance this robs from the application.  Yes, I do think you can develop things much faster in this way and I think it does a lot to make PHP a bit Ruby on Rails like.    But I think it’s better geared towards virgin PHP development houses that don’t really have the architecture experience that they should.  I’m all for more people doing things the right way.  But if you already know the right ways than being shoehorned in to a slightly constrictive, buggy, and not well documented framework is a bit of a negative experience.

And it relies too heavily on PEAR to do any of the things I’d really like out of a framework.  Symfony really needs a robust library to back it up.  The kind of thing any old PHP framework has.  XML libaries, unit testing, queing, date manipulation, IP services, etc.  I haven’t used too many frameworks in the past but I know that other PHP frameworks just ‘have more’ tied in to them.

I’m just not sure there’s enough people in the community to really give any PHP framework the attention span it deserves.  Too many differences of opinion I guess.

Jan 2
In Project Review: Video Channel
posted by: Player0 in javascript, php, projects on 01 2nd, 2009 | | No Comments »

I got talking about video in my last post and I couldn’t help but to start thinking about my endeavors with a previous employer.  In fact, it was some of the most interesting work I’ve done for any company.  In 2006, I was working for Synacor out of Buffalo, NY.  They provide web portals for major ISPs so their cable modem customers have an AOL-like experience.  Internet video was already very big with YouTube’s success and AOL’s video channel right around the corner.  Cable companies have access to all sorts of great digital media but don’t really have an avenue for delivering that to internet customers.  I was brought on to the video project to take the existing product and bring it in to modern times.

The resulting product can be seen here.  As of this writing, not much has changed from my original designs even though they are several years old.  Like all my internet creations I’m sure it will morph in to something unrecognizable soon enough.  And like most of my internet creations, management stepped in to make several surface level decisions about layout and advertising.

I should be clear about what I did on this project because I want to give credit where credit is due.  I didn’t write the framework from the ground up.  I built around what was originally there.  I made many changes to the database schema apart from the word search index which I wasn’t scheduled to get to just yet.  I beleive I rewrote most of the PHP and created all the APIs and JS from scratch.  I had nothing to do with the design of the page since we had a design team but I did do the HTML and CSS.  I did a little AS programming for the Flash Media Player but left much of that up to their talented flash developer.  And I left the company before totally completing the new version of the video product.  Integration with the flash player was not complete and there were a couple other minor features that didn’t work yet.  Mostly this revolved around tying the video product in to the Synacor’s various incomplete CMS products.

With that said, and although the credit was stolen from me, I architechted the overall product.  From getting videos on digibeta tapes for from FTP uploads, transcoding them, and feeding them in to our front end database, to ajax-ifyign the user interface with an event listener model so the page layout was modular to speccing out exactly how the flash media player should integrate with the XML for a content rich experience.  And the neat feature of having the video player pop off of the page and allow you to drag it around and change aspec ratios… that was my idea too.  I designed it to function like a stand alone media player application.  The player window would load a Flash or a Windows Media player object and make this as transparent as possible to the user.  And you’d have all the basic controls you’d expect from a standalone media player.  It’s not amazing but it’s a pretty neat user experience and not one I’ve really seen anywhere else.

The modular aspect of this page is the most underrated part.  This video product is meant to be used for a variety of customers and each wanting customizable features.  If you want a horizontal and/or a verticle channel bar, you can.  If you want multiple video indexes or just one, you can.  If you want to spotlight 10 videos or 1 video you can.  Templates control the whole thing and you simply enable modules from the CMS system.  Each module on the page, the channel bar, the video listing index, the spotlights, the channel specific ads, etc all listen to the states of the other objects that happened to be published on the page and DTRT accordingly.  The page still uses the sheep.js event handler I wrote.  And I’m singularly impressed with how fast all the ajax is on the page.  There is a lot of background preloading and caching and pagination happens on the client side.  A weird arrangement and potentially risky but the datasets are constrained and seem to be lightweight.  Perhaps they are cached and/or gzipped at this point.  The ajax is serving raw HTML as well which is a bit strange.

And I’d do things very differently these days.  I’m glad to say I’ve come a long way in the past few years.  If I could do things differently I’d have fought harder for Prototype/jQuery/YUI or some other JS standard.  I would have used JS’s event model instead of using my own.  I would have used libary JS effects from script.aculo.us or something.  I certainly would have used JSON with the ajax requests.  I certainly would have tried to get memcached working and I certainly would have tried to get them on Akamai or some other decent static content delivery system.  I still would have suffered trying to integrate this thing in to the custom CMS products though :)  Most importantly, I probably could have done this project in a quarter of the time by applying those techniques.

It was really fun work and I miss doing it.  The company just wasn’t a great fit for me at the time though.  They were waterfall method which meant I was writing a lot of useless documentation, releases were months apart and I dealt with more red tape than programming.  I could have gone at 10x the pace.  I did not get along well with my product manager who was hired as a ‘hotshot’ from AOL.  She played the game well.  She rested on the laurels of others and functioned solely as funnel for information.  A one way funnel.  My ideas became her ideas.  My timelines became hers.  My specs became hers.  My success became hers.  And when the video product was launched and there was a party, kudos were given to several management types by name.  And I, having done at least 80% of the projects work, received his thanks in the way of ‘…and everyone else who made this possible’.  An architecht who did nothing more than review my spec for about 5 minutes was thanked by name for his incredible help on the project.

This product manager left not too long after I left.  She wasn’t going to deliver much without me.  Always end on a high note I guess.  I’ve never had such a problem with a company before or since.  I honestly think I was cursed at Synacor for some reason.  I always felt so underestimated.  I always succeed very well with other companies but I just couldn’t make it work there.  I think first impressions are everything and I didn’t give a very good first impression there when I started I guess.  It had been a while since I worked for a larger company and I was a bit intimidated and I had problems communicating with the others because I was behind on the jargon.  That was rectified 6 months in but I think the stigmata stayed with me for the rest of my two years there.  And beleive me I tried.  I *always* try.  My complete and utter lack of energy to move in the AM makes it looks sometimes like I don’t try but I really do try to prove and better myself every single day.  As long as companies don’t mind me coming in at 10:15am, and staying later of course, I’ll continue to do just fine :)

Dec 10
The Statics Are Always Late!!
posted by: Player0 in php on 12 10th, 2008 | | No Comments »

I simply cannot wait for PHP 5.3 to be released in some stable form.  I can only hope that we can start using it right away in my company as well but those are high hopes I think.  There are a lot of reasons that 5.3 should be better.  A couple things I’m looking forward too.

1.) $class::method()

2.) __callStatic()

3.) Late Static Bindings

I really hope the latter addresses a serious problem when it comes to PHP and static class inheritence.

class a {
static $var = ‘monkey’;
static function doSomething() {
echo self::$var;
echo __CLASS__;

class b extends class a {
static $var = ‘hate’;


What is output in PHP 5.2.6?

class a

That’s terrible!  I did manage a work around for class b:

class b extends class a {
static $var = ‘hate’;
static function doSomething() {
parent::$var = self::$var;

But that’s pretty ugly.  There are some cases where you really want static class inheritance like this.  Here’s hoping for a fix in 5.3.

Another minor thing that grave me trouble recently was the lack of read-only class members.  It’s probably a rare problem but one that other languages provide solutions for.  It’s not always ideal to do all access through get accessors.

Nov 7
Monkey Hate PHP
posted by: Player0 in php on 11 7th, 2008 | | No Comments »

Ugh, I’m really starting to lament my choice to be a PHP developer.  Sure, it *is* better than Perl and who knows if I should learn Python, Ruby or Java.  I found a little nugget of joy today when using PDO and ip2long().  If you simply do a $sth->bindParam(’:iplong’, $iplong); the query my receive something like -42452 which won’t work.  This issue is complicated by the fact that, as far as I can tell, PDO provides absolutely no method for viewing any query with the parameters replaced before or after you exec() it.  Also take note that without a 3rd parameter, bindParam is supposed to work in PARAM_STR mode.

But, due to the mysteries of type conversion and PHP’s utter inability to deal correctly with any number much larger than 2 billion, you must do:

$sth->bindParam(’:iplong’, sprintf(’%u’, $iplong), PDO::PARAM_STR));

More issues arise in PHP land when you try to take advantage of the fact that MySQL developers aren’t necessarily inbred.  Take, for example, a BIGINT(20) column type.  There’s no real reason why this 64bit integer isn’t a commonly used data type.  If you have a table with auto_increment IDs and you delete from it regularly than BIGINT is a must.  Or suppose you want 64 enable/disable bits for some reason.  Well you can treat them as strings in PHP as long as you don’t EVER try to use them in something which is going to assume they’re numeric.  And forget adding, subtracting, bitshifting, etc without BCMath or some equivilent extension you’ll be lucky if is ever compiled in to your PHP install.

This is ignoring the glaring problem of platform specific architecture and PHP’s retardation in abstracting that.  Your (int)s on x64 might be 64 bit or they might not be.  Nothing is guaranteed.

I heard that PHP6 fixes a lot of UTF8 stuff.  I suppose it’s too much to ask for it to add a 64bit integer type.

Nov 3
No Fallout 3 Yet
posted by: Player0 in php, projects on 11 3rd, 2008 | | No Comments »

I’m sitting here annoyed by several things.  First of all, several of the keys on my keyboard, especially backspace, have developed a case of the stickies.  Someone spilled something on this thing and it wasn’t me.  A more important annoyance is the fact that I have still not played Fallout 3, or any of the other Fallout games.  I’m quite interested to see what Bethesda hath wrought.  But alas, I am poor, for I purchased a new PC for my wife for her birthday.  Really, I just wanted her to be able to play WAR and WOW with me.  I suspect she is somehow involved in this sticky keyboard fiasco…

I have a bunch of older computer parts hanging around especially since I gutted my wife’s PC.  I decided to buuld myself a dev box which I could bring to work.  It would be nice to offload some of my work PC’s duties to a separate machine.  Primarily the hosting of dev environments.  Also since I prefer to have my work PC running Windows for various reasons, having a second box provides me with an avenue to use linux when I need.  Especially for those dev environments.

The Windows command prompt sucks absolute balls.  Yeah, there are some replacements out there.  Cygwin is barely okay as well.  Running linux is nicer.  Especially when it’s not a virtual machine eating up every available ounce of CPU, memory and disk access.

The wife’s machine donated an Opteron 146 and some Nvidia S754 motherboard.  I had a couple SCSI3 discs and a controller laying around.  A PSU here, a DVD-ROM drive there, and a stick of the world’s cheapest DDR 1G RAM and I have a pretty powerful dev box.

Linux tends to disagree with it.  First up was CentOS 5.  This actually installs and does the software RAID 1 like I would like.  But for whatever silly reason it hates the ATI 9200SE video card I’m stuck with and my MS mouse doesn’t work with it.  So I tried Ubuntu.  The mouse works but the screen goes all flickery and it’s just not installable.  So I give Gentoo it’s shot.  First time I ever tried it.  Ugh.  It’s for maniacs.  Who has this kind of spare time??  Really, I mean, I’m sure it’s awesome once you get it going but I think that the effort is just too much.  I really don’t want to do software RAID1 partitioning manually, I’m sorry.

With my options dwindling I’m left downloading Fedora Core 9.  With any luck it’s modern enough to work with all my crap out of the box so I just don’t have to fight with anything.  We’ll see in a few minutes.  I had the DVD but it won’t boot in this old drive of mine (Creative 8X DVD that’s over 9 years old now and came with a hardware MPEG2 accelerator).

At work I’m now officially an architect.  I’m not sure what that changes necessarily but it means I have to learn entirely new software deployments.  In many ways it’s like working for a completely different company.  I’m also learning Symfony.  I’m trying *real* hard not to be skeptical about it but there are things already I do not like about it.  Perhaps this is an implimentation thing but Syfony loves loading entire MySQL record sets (and corresponding objects) in to memory.  It doesn’t seem well optimized.  But I know so little about it that I can’t really speak beyond it’s seemingly high memory usage.  In many ways, I am not a believer in PHP frameworks.  PHP itself is a language designed to be used for rapid prototyping.  By forcing developers to learn and fight with something beyond PHP aren’t you slowing them down?  It certainly hasn’t done me any favors as I jump on to this project as a total noob.  However, I agree that there are many common tasks that need to be built over and over in PHP these days.  Shared sessions, i18n, db abstraction, cms. db/object reflection, release management, scheduling/queuing, etc.  If you think about it, the problem probably lays with PHP itself.  If PHP is a rapid prototyping language than it should have more built in.  It should be more API like.  If PHP is supposed to be a lower level language than it needs to be less bloaty, but perhaps better structured.

PHP is just a seriously confused language I think.

Dec 8
Philosophy of PHP
posted by: Player0 in php on 12 8th, 2007 | | No Comments »

Computer languages are flexible beasts.  PHP is no exception and it’s because of this fact that I have a real problem developing a real coding style in PHP.  I believe that PHP was developed to speed web development.  To make web development easier.  It succeeded in spades.  PHP has become the joke language in place of JavaScript.  Anyone’s mother can create a site and add some PHP elements.  You don’t have to understand PHP to add a <?php date(’Y'); ?> on to your site.

PHP, thanks to it’s success as well as Zend, has grown in to larger beast with OO and all sorts of modules and CLI.  And immediately we run in to a problem: PHP is slow.

It all comes down to how enterprisey you think you need to be.  Sure, abstract classes and design patterns and throwing errors is all nice and good and flexible.  But they all make for slower applications.  They also make for slower development processes.

Then ask yourself WHY are you using PHP?  If you want security and speed and UTF-8 and enterprisey, isn’t Java a better choice?  It’s not that much harder to compile code people.

I may be a PHP purist.  I want to keep PHP quick to develop and simple to maintain.  I do like classes because they add name spacing and organization.  But we don’t NEED to be fancy and more than one function call per function is a bad thing.  I don’t want to give up foreach loops for performance reasons.

Yet so many companies build these massive frameworks and OO models which are meant to reduce programming needs down the line but ultimately become these huge elephants that are shot in the chest after it’s discovered that PHP can’t actually manage firm business requirements such as internationalization or code security.

If you let the programmers just build something that works and is at least fairly well done even in a simple way then let feature creep happen you’d be better off.  If you can develop PHP fast then it doesn’t matter if you have to reinvent the wheel a couple times.

PHP shouldn’t be called a joke language but it certainly doesn’t deserve to be treated enterprisey either.  Please stop abstracting your database layers three times just in case you decide that MySQL really does suck and MIGHT go to Postgres or Oracle someday.  If you didn’t wrap every DB call with insanity it might not be so slow.

On that note, does anyone know when PDO will start using the native MySQL drivers?