Search code examples
phpuniquezend-server

PHP uniqid() no longer unique after updating PHP to 5.3.26


Anyone else discover that PHP is no longer producing unique values for uniqid() after updating to 5.3.26? My previous version was 5.3.16.

It's not a minor problem. My DOM IDs are generated with that function for all jQuery UI Buttons, and a lot of them have duplicate IDs.

I've changed the code from uniqid("button") to uniqid("button",true) but it didn't change the results. Still getting duplicate IDs.

This happen after updating Zend Server free edition to the latest build.

Is there a solution to this? Refactoring the code to use integer counters is not a small task, and means I have to retest everything.


Solution

  • Okay, I was able to fix my problem by doing the following.

    Change:

     $id = uniqid('button');
    

    To

     $id = str_replace('.','-',uniqid('button',true));
    

    That includes an extra number appended with a dot. Which creates invalid DOM IDs (in my case) so I just replace it with a dash.