0

I've been tasked to migrate an old PHP4.3 site (using CVS version control) to a more modern 5.2 install (lower version number for compatibility issues) on a shared GoDaddy server. I've gotten through most of the issues, but this particular one is a tough nut.

Inside the administration view, there is an export to excel function which uses the Spreadsheet_Excel_Writer (0.9.3) PEAR package. However, this line keeps throwing a fatal error:

aggregate( $sheet, 'Spreadsheet_Excel_Writer_Sheet_Patch' );

where $sheet is defined by

$sheet =& $xls->addWorksheet( 'Customer Data' );

My issue is that aggregate no longer exists in PHP5, and I cannot install runkit as I do not have root permission to execute the pecl install command on the server.

I'd rather not have to rewrite the existing functionality, so is there a drop-in replacement for aggregate that I can install without requiring root permissions?

Jason
  • 11,263
  • 21
  • 87
  • 181
  • `I've been tasked to migrate an old PHP4.3 site to a more modern 5.2 install` - I should point out that 5.2 is still not modern. If the aim is to move up to a supported version, then your minimum version today needs to be 5.3, but even that will be out of support in the relatively near future. You may be aware of this anyway and happy to only go to 5.2, but I feel it's important to point out, as 5.2 has not had any patches in three years, and has some significant known security holes that I really wouldn't want on my site. (nothing compared to 4.x of course, though!) – Spudley Apr 18 '14 at 14:41
  • thus the qualifier `more modern` in my statement :-) As this is an internal, non-billable task, the less work required the better. Finally, the website contains no sensitive information, financial or otherwise. – Jason Apr 18 '14 at 15:02
  • Fair enough :) hehe. All the same, I'd be pretty certain that your best bet here is to switch to a more modern excel lib rather than trying to stick to that old crusty one. And most 3rd party libs these days have a minimum requirement of 5.3. So in that respect you might actually be making things harder for yourself by restricting to 5.2. – Spudley Apr 18 '14 at 15:08

1 Answers1

1

With regard to the Excel library you're using, you will need to upgrade that to a version that supports PHP5, or else migrate to an alternative library. There are several Excel libraries available which do support recent PHP versions, so you should probably investigate those.

I won't recommend any specific library now, as I haven't worked with any of them for a little while and so my recommendation may not be the best. And in any case, your needs may be different to mine. Instead, simply googling for 'php excel' will give you plenty of results to help you find a library to suit you. You will obviously need to rewrite your code where it uses the old library so make it work with whatever new library you choose, but that will be infinitely easier than trying to make the old library itself work. (also, newer libraries will support newer excel versions, which is probably quite important; things do move on)

I certainly wouldn't recommend trying to keep using the existing library; it's clearly written for PHP4, and would likely be a very difficult task to bring it up to date.

You mention runkit: that wouldn't likely be a good solution here even if you were able to use it. For something closer to what the aggregate() function does, you might want to investigate the Reflection class, which allows some similar class- and object-level trickery, but in general well-written code shouldn't need that kind of thing anyway (it may have done in PHP4 days, but much less so today).

Another alternative to aggregate() might be the Traits feature in PHP 5.4 and up. This can give some of the multi-inheritance functionality that aggregate() was sometimes used to simulate. Obviously, you'd need to upgrade to 5.4 for this though, and the actual code you'd write would be quite different.

Spudley
  • 166,037
  • 39
  • 233
  • 307