May 8
PHP Meetup
posted by: Player0 in php on 05 8th, 2008 | | No Comments »

I went to my first PHP Meetup last night here in Boston.  It was an interesting experience and in may ways what I had expected.  I think I could go again but only for a topic that truly interested me.  I’d be more inclined to like something a bit more hands on or workshop like.

One of the topics of most interest last night revolved around migrating from PHP4 to PHP5 without a major overhaul of the code base.  PHP5 is mostly backwards compatible after all.  Well one of the problems encountered by my company was the fact that many of our static function calls were not defined with the static keyword since it doesn’t exist in PHP4.  This throws an E_STRICT in PHP5 and was the cause of huge performance losses.  Adding the strict keyword where ever appropriate solved the performance issues.

But a couple things I’ve noticed about this were not mentioned last night.  For one thing, E_STRICT has the tendency to core dump PHP5 when it’s enabled for logging.  This seems to happen on all the latest versions.  While the core dump itself is not necessarily the cause of the slow down, it’s another weird side effect of the PHP5 migration since E_STRICT will happen a lot in old PHP4 code bases.

A slightly smaller issue revolves around PHP5s terrible OO implementation.  The lack of function overloading is absolutely crippling sometimes and this especially affects cases where a function may work best as a static call AND an instanced call.  This is a rare desire but I ran in to it the other day where the object class is sometimes instantiated as an object but sometimes instantiated as a singleton.

There are ways around this.  First off you could always statically serve an instanced copy of the object.  This wasn’t ideal in my situation.   It is also possible to not use the static keyword.  This allows the function to work statically or instantiated but it’s going to throw E_STRICT every time.  Using $this inside the function is going to throw E_ something itself.  You can use a conditional to only use $this when the class is not being called statically so it won’t error but it’s simply not going to like $this being in there.

PHP made a mistake by making missing static an E_STRICT event I think.  There might be cases where you don’t want to make it static.  It would be nice to disable the $this exceptions as well for these cases.  But better yet, PHP would be a much better place to live if it offered function overloading.