views:

108

answers:

2

Hi folks

I've built a ZF app using 1.10 for deployment on RHEL server in a corporate client, which has PHP 5.1.6. It won't run.

I googled and now realise it's the version of PHP. I didn't realise ZF had a minimum requirement for PHP 5.2.4, and calls to HeadLink seem to be causing fatal error "Call to undefined method Zend_View_Helper_Placeholder_Container::ksort()":

PHP Fatal error:  Call to undefined method Zend_View_Helper_Placeholder_Container::ksort() in /library/ Zend/View/Helper/HeadLink.php on line 321

The client won't upgrade their PHP; I don't want to rewrite the app without ZF, and I'd rather not downgrade ZF to a grossly earlier version.

Is there some patch I can use to add ksort() to ZF 1.10 to get around this? There may be other problems, but this is where I'm stuck right now.

Any advice welcome

Many thanks

Ian

EDIT: As I say in a comment below, I expect many people have hit this before and will keep on doing so as RHEL5 will be a standard in corporate environments for a good time to come. I was hoping for a link to an existing solution rather having to devise one from scratch.

UPDATE: I used the patch linked to in the accepted answer and it fixed the problem for me.

This is adding the following public method to Zend/View/Helper/Placeholder/Container/Abstract.php

    /** 
 * Sort the array by key 
 * 
 * @return array 
 */ 
public function ksort() 
{ 
    $items = $this->getArrayCopy(); 
    return ksort($items); 
}

There was one remaining issue; a PHP notice caused by a string conversion in Zend_View_Helper_Doctype. Comparing this function to similar ones above and below, this seems to be an error in the library

public function isHtml5() {
    return (stristr($this->doctype(), '<!DOCTYPE html>') ? true : false);
}

Changed to:

public function isHtml5() {
    return (stristr($this->getDoctype(), '<!DOCTYPE html>') ? true : false);
}

Patching the library itself was the last thing I would normally do, but in this case it got me out of a spot. We'll make sure the patch is versioned in the repo and documented obviously for future developers.

+2  A: 

I suppose you could change the inheritance of Zend_View_Helper_Placeholder_Container or Zend_View_Helper_Placeholder_Container_Abstract to supply your own implementation of ArrayObject::ksort. Something like:

class CompatibilityArrayObject extends ArrayObject {
    public function ksort () {
        // here be dragons
    }
}


abstract class Zend_View_Helper_Placeholder_Container_Abstract
extends CompatibilityArrayObject {
    ...
}

You don't know how many more problems there are though. If the requirement says PHP 5.2.4, that's what you should run it on.

deceze
@deceze - thanks, this is the sort of thing I was wondering about. But I am sure many people find themelves in this boat; RHEL 5 is going to be the standard in many enterprise environments for a good time to come. I was hoping someone could direct me to a complete solution; I don't want to reinvent the wheel extending ZF, since after all the entire point of ZF is to avoid reinventing the wheel
Flubba
+2  A: 

Hi,

I had the same issue today. I found solution in this blog post.

Add the following snippet in /Zend/View/Helper/Placeholder/Container/Abstract.php:

/**
* Sort the array by key
*
* @return array
*/
public function ksort()
{
    $items = $this->getArrayCopy();
    return ksort($items);
} 
Naktibalda
+1 But the core issue remains: You don't know how many more incompatibilities there are.
deceze
@deceze - the core issue is that the ZF team in their ivory tower decided to break compatibility with earlier PHP versions, in the full knowledge that there were a great many production environments like the one discussed here where they CANNOT CHANGE THE PHP VERSION installed or they lose the support warranties from Red Hat and their hosting provider. They won't upgrade the PHP, so the alternatives are patch ZF to work or rewrite the app without ZF. Which would you rather do in my place?
Flubba
@Flubba The problem with patching is that it's hard to know when it's done. You will need to do a lot of testing to make sure you patched every missing requirement. I'm not saying it's not the solution, I'm just pointing out the drawbacks. You're stuck in a pretty bad place, so you need to weigh all pros and cons. How hard would it be to port the application to an older version of ZF? That may be a task with a better definable scope.
deceze
@deceze - thanks... I'm not disagreeing with your appraisal of the drawbacks. I'll consider downgrading the ZF to an earlier version but at the moment patching is less work and timescales are tight. This resource looked useful: http://zfcompat.wolf-u.li/ but it doesn't actually show the minimum required version for Zend_View_Helper, so needs to be taken with a pinch of salt. Thanks for your answer; I've upvoted it but accepted the other one because it linked to actual code. Thanks for your help!
Flubba