Today I decided to check how Emergence would run in PHP 5.4. I started with a private virtual machine I have for my own personal portfolio. It's a simple virtual machine with only 1GHZ of guaranteed processing power and 512MB of guaranteed memory. I use Gentoo on this virtual machine so portage is the default package manager.
I started by running this command just to see what would happen.
sudo emerge dev-lang/php:5.4 --ask
Portage complained a little about not having =dev-lang/php-5.4.0 ~amd64 in the /etc/portage/package.keywords file.
After I added that line to package.keywords I was able to compile PHP 5.4.0 no problem.
After compiling portage reports that you will need to run this command to set apache to use PHP 5.4
sudo eselect php set apache2 php5.4
You will also need to run this command to set PHP 5.4 as the default command line version of PHP.
sudo eselect php set cli php5.4
Afterwards running php --version should yield
PHP 5.4.0--pl0-gentoo (cli) (built: Mar 6 2012 22:36:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
At this point I ran sudo /etc/init.d/apache2 restart to check on how things were running before moving on.
The first thing I noticed was that the pecl extension apc wasn't working. The error I was getting was that a function that is part of apc doesn't exist. In Gentoo portage installs apc for you with the command
sudo emerge dev-php/pecl-apc however it wasn't properly configuring with PHP 5.4. Instead I had to get the pecl command line utility so that I could install it with pecl instead of portage. To do so I ran sudo emerge dev-php/pear. This command went onto install 6 relatively small packages that allowed me to then go onto run sudo pecl install apc.
At this point I actually had two versions of PHP on the machine at the same time but I had set 5.4 as the default in both apache and command line.
Portage likes to create separate configuration folders for each version of PHP installed so at this point a directory listing of /etc/php yields
drwxr-xr-x 4 root root 4096 Jan 9 20:27 apache2-php5.3
drwxr-xr-x 4 root root 4096 Mar 6 22:41 apache2-php5.4
drwxr-xr-x 4 root root 4096 Jan 9 20:27 cli-php5.3
drwxr-xr-x 4 root root 4096 Mar 6 22:41 cli-php5.4
These folders contain the respective php.ini file for each of the given versions of PHP. Since the 5.4 install was fresh I knew I needed to configure a few things in the php.ini file first.
First I set the timezone to avoid the warnings PHP throws anytime a time function is used without this setting.
date.timezone = America/New_York
Since I installed apc manually with pecl I also had to add extension=apc.so to the php.ini file.
Then I went to the error reporting.
At first I set it to
error_reporting = E_ALL & ~E_NOTICE
But I was getting two peculiar errors from this. One of the errors is well documented in this bug report from PHP 5.3. Specifically when running PHP in strict mode it will report errors when you try to define a static abstract function. The reason for this as rasmus himself explains:
[2010-10-16 07:15 UTC] rasmus@php.net
A static method belongs to the class, not to an instance of that class and since
you can't have an instance of an abstract class, static methods make no sense in
abstract classes. It is really that simple.
Personally I find this thinking to be stuck in the past and has a lot to do with the way OOP works in Java. Since by definition you are potentially redefining the method when extending the class it makes a lot of sense that you might choose to make the original an abstract method simply to force the new extended class to contain the said function.
Emergence uses this pattern for it's controllers. With the top level controller class being an abstract class RequestHandler containing an abstract static function handleRequest. Therefore any newly created class which extend RequestHandler must define their own static function handleRequest.
The other error that is actually new in PHP 5.4 has to do with having different parameters in the methods of an extending class from the parent. For example one of the errors was:
Declaration of User::save() should be compatible with ActiveRecord::save($deep = true)
The error was thrown by PHP because the child method save() in class User didn't contain the parameter $deep = true. Fortunately I later found out that removing E_STRICT errors in php.ini would suppress this issue.
So finally after running into these issues and changing error_reporting in php.ini to this value I was able to get Emergence to fully load.
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
The issues I ran into were relatively small and when E_STRICT error reporting was disabled I was able to run the Emergence code base without issue. I'm looking forward to playing with traits.























