ZF-5883: Headlink.php line 310 ksort throws error

Issue Type: Bug Created: 2009-02-25T07:34:40.000+0000 Last Updated: 2009-07-31T12:42:14.000+0000 Status: Resolved Fix version(s): Reporter: Christian (cs45977) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

Related issues: - ZF-5992



The ksort in toString on Headlink.php can cause an error Fatal error: Call to undefined method Zend_View_Helper_Placeholder_Container::ksort() in /library/Zend/View/Helper/HeadLink.php on line 310. Once commented out there are no errors.

Code calling headlink below:

    $this->headLink()->appendStylesheet('<a rel="nofollow" href="">;</a>');
    echo $this->headLink();


Posted by Andris Causs (cypher) on 2009-02-25T08:08:42.000+0000

The same happens in HeadLink (line 310), HeadScript (line 449), HeadMeta (line 332) and HeadStyle (line 365). The ArrayObject does not imply ksort function and thus it cannot be called:

A temporary fix is to add a function to /Zend/View/Helper/Placeholder/Container/Abstract.php.

Posted by old of Satoru Yoshida ( on 2009-02-25T20:04:20.000+0000

Set component and auto re-assign

Posted by Jay M. Keith (jmkeith) on 2009-02-27T07:58:45.000+0000

This appears to be an issue related to the version of PHP being ran. I had this error occur when running on PHP 5.1.6.

Posted by Matthew Weier O'Phinney (matthew) on 2009-02-27T08:18:34.000+0000

ArrayObject implies ksort with PHP 5.2.0 and above. Though we no longer support PHP below 5.2.4, I suspect that this code has been in place for some time before 1.7.0. I'll see if I can post a patch to the issue for those using prior PHP versions.

Posted by James Wade (hm2k) on 2009-03-11T08:02:55.000+0000

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

To reproduce I have the following files:……

The latest version of PHP with CentOS 4.7 is PHP 5.1.6, this is due to backporting (

Included in the framework, the README SYSTEM REQUIREMENTS says:

Zend recommends the most current release of PHP for critical security and performance enhancements, and currently supports PHP 5.2.4 or later.


Zend Framework requires PHP 5.1.4 or later.

Both documents point to… which says:

Zend recommends the most current release of PHP for critical security and performance enhancements, and currently supports PHP 5.2.4 or later.

Although this recommends a version, it does not have a minimum requirement.

By searching the files, I found some requirements for PHP 5.2.0 or above...

findstr /s PHP_VERSION . library\Zend\InfoCard.php: $base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>='); library\Zend\InfoCard\Xml\Security.php: $base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>='); library\Zend\InfoCard\Xml\SecurityTokenReference.php: if(version_compare(PHP_VERSION, "5.2.0", ">=")) {

This is all kind of off putting for someone new to this framework, when there's no strict guidelines as to which version you're meant to use, a lack of backwards compatibility, and no basic version control error checking. Disappointing.

All this aside, looking at the actual error itself, it says that ksort() simply isn't defined, even though the PHP native function has existed since PHP 4.

On line 310 I see the following:


I searched the entire of the library and could not locate anywhere that defines ksort as a function within the class.

The term "function ksort" does not exist in any of the files included in the downloads, thus it's clearly not defined.

This is clearly an issue which has existed since 1.7.5 and has still to be addressed...

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-11T08:25:54.000+0000

ksort() is defined in ArrayObject, which is an SPL class. However, it was added in the PHP 5.2.x series -- which is why the error occurs in PHP 5.1.x versions and not PHP 5.2.x versions.

I will look into why the upped version requirements are not reported in the 1.7.x release notes -- that said, it was a major part of our messaging for the 1.7.0 release.

Posted by James Wade (hm2k) on 2009-03-11T09:28:44.000+0000

Is there any reason why it needs to use SPL ArrayObject's ksort() over the native ksort()?…

This seems to suggest not.

Posted by James Wade (hm2k) on 2009-03-19T04:21:36.000+0000

Is Zend Framework going to have any kind of backwards compatibility or am I expected to upgrade and recompile PHP to bleeding edge each time I use the latest version?

Posted by Jon Whitcraft (sidhighwind) on 2009-03-19T04:39:13.000+0000

The ksort fix was put in place for ZF 1.7.5 (

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-19T05:53:08.000+0000

Jon -- if this was indeed fixed for 1.7.5, could you please mark this issue as resolved? Thanks!

Posted by Jon Whitcraft (sidhighwind) on 2009-03-19T05:58:11.000+0000


I think I misspoke. I put the ksort code in place for 1.7.5 which caused this error on php 5.1.x. With ZF only supporting php 5.2.4 as the minimum now should a fix be put into place to make it use the native ksort instead of the SPL ksort?


Posted by Bernt Pettersen (burnie) on 2009-03-30T07:32:19.000+0000

grep -B 1 'PHP 5' ZendFramework-1.7.7/*.txt


ZendFramework-1.7.7/INSTALL.txt:Zend Framework requires PHP 5.1.4 or later. Please see the system requirements

ZendFramework-1.7.7/README.txt-Zend recommends the most current release of PHP for critical security and ZendFramework-1.7.7/README.txt:performance enhancements, and currently supports PHP 5.2.4 or later.

I guess this could be the actual issue?

At least it fooled me into thinking I could run ZF 1.7 on a server running CentOS 5 (php-5.1.6) - Now this gives me the feeling ZF 1.7 isn't meant to be used in a production environment...


Posted by Matthew Weier O'Phinney (matthew) on 2009-03-30T07:52:24.000+0000

So, first off, I will correct the INSTALL.txt file today to correctly reflect the minimum supported PHP version (5.2.4).

Second, as to your jab about "this gives me the feeling ZF 1.7 isn't meant to be used in a production environment", we carefully considered the benefits and pitfalls of upping the minimum supported version. At this time, the only major distributions still shipping a PHP 5.1.x version are... RHEL and CentOS. And RHEL will not be releasing a new version with an updated PHP version until sometime in 2010. 5.1.4 was released almost 3 years ago, and many improvements and fixes to the language have been released since then; to be honest, 5.2.4 was shipped over 18 months ago, and many improvements have been made since then. However, in our review of distributions -- including many Linux, *BSD, and other *nix variants -- most were shipping at that version or newer, including now Debian Lenny.

Jon -- no, do not back out the change. Since the minimum supported version supports SPL's ksort, we can use it.

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-30T07:55:49.000+0000

Updated INSTALL.txt to correctly show minimum supported version; current ksort() usage is correct per our minimum requirements.

Posted by James Wade (hm2k) on 2009-03-30T09:16:20.000+0000

1, Was this a documentation issue then? 2, Will the website documentation change to say "requirement" instead of "recommend"? 3, Will there be no backwards compatibility legacy support? 4, What are the recommendations for RHEL and CentOS users? -- considering that RHEL and CentOS are very popular for production web servers. 5, Are you going to introduce any "compatibly" checks? -- this will help avoid issues like this in future.

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-30T10:39:23.000+0000

  1. Yes -- the INSTALL.txt was out-of-date with other documentation, including our own manual and the README.txt file.
  2. The website already says that 5.2.4 is required for versions 1.7.0 and above.
  3. We will only backport security fixes to previous branches, but not bugfixes.
  4. RHEL has more up-to-date packages via its paid support channels. Additionally, a number of semi-official channels for both distros have more up-to-date PHP packages as well -- including Oracle's repositories. Finally, third party vendors such as Zend are offering supported AMP stacks that may be used with RHEL and CentOS.
  5. What sort of compatibility checks to you suggest?

Posted by Bernt Pettersen (burnie) on 2009-03-30T10:47:36.000+0000

Ok. (Matthew, sorry for venting my frustrations :)

I think this only is/was a documentation issue, but I also second James in adding some version checking. And since Mattew now has illuminated me, I will really consider upgrading to php 5.2 on the EL5 machines. I think the improvements would be worth it, and I think it will be less effort than "backporting" ZF to php5.1...

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-30T11:13:36.000+0000

Bernt -- no worries. I understand the frustrations entirely. On the flip side, the fact that some distros offer no ability to upgrade PHP versions (which are actually very much BC between versions in the same major revision) is incredibly frustrating to component library and framework developers, as they prevent us from using up-to-date language features, and in effect can hamper the uptake of said features. At a certain point, we have to decide between progress of the framework and supporting all available versions -- and the latter is in many cases a Sisyphean task. (Much like supporting browser versions in Javascript and CSS...)

Posted by James Wade (hm2k) on 2009-03-30T12:30:17.000+0000…

Zend recommends the most current release of PHP for critical security and performance enhancements, and currently supports PHP 5.2.4 or later.

The website says "recommend" not require.

With regards to upgrading PHP on CentOS:

For CentOS 4: cd wget -q -O - | sh yum --en=atomic update php

For CentOS 5: cd /etc/yum.repos.d wget yum --en=c5-testing update php

With regards to compatibly checks...

if (version_compare(PHP_VERSION, '5.2.4, '<') { die('Zend Framework is not compatibly with your version of PHP, please upgrade.'); }

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-30T13:22:27.000+0000

@James Wade: The operative part of that sentence is "supports PHP 5.2.4 or later". That's a requirements statement. The verbiage "recommends" is related to "the most current release".

Thanks for the information on upgrading PHP on CentOS -- that will be useful for many.

As for your compatibility check... where would that go, exactly? There is no single god class in ZF that is used by every single component. While I think that the version check could be nice functionality, I hesitate to push a global dependency into the framework.

Posted by James Wade (hm2k) on 2009-03-30T14:12:55.000+0000


"supports" and "requires" are not one of the same:

I support PHP, but I do not require it; I require food, but do not support it.

The compatibility check only needs to appear in the classes that compatibility is an issue, in this case...


If this file requires 5.2.4 or above, it should check for it; otherwise as we know, it won't work.

However, what I fail to understand is that ksort was added to SPL's ArrayObject here:…

By the looks of it, it was added into PHP 5.1, so why it won't work in 5.1.6 I'm not entirely sure.

Posted by Brian Tipton (tiptone) on 2009-07-31T12:38:44.000+0000

I'm not seeing that this issue is closed.

I'm using a fresh download of ZendFramework 1.9 on a RHEL 5.3 machine with PHP 5.2.9 from Centos-5 Testing repo.

From the most recent Quickstart guide:


headLink()->appendStylesheet('/css/global.css') ?> Puts the following error in the Apache error\_log:

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

I've verified that ArrayObject is present in the PHP release I'm using with the following test script:

$foo = array('a' => 'Aye', 'b' => 'Bee', 'c' => 'See'); $obj = new ArrayObject($foo); $obj->ksort();

Which seems, to me, to imply that in Zend/View/Helper/HeadLink.php on line 311:


$this->getContainer() is not returning a reference to an ArrayObject.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-07-31T12:42:14.000+0000

That would be a different issue I think. PHP <5.2.4 is simply not supported, and that's what this issue about. I think you should add a different issue for your point.

Have you found an issue?

See the Overview section for more details.


© 2006-2020 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.