Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

uniqid() only provides a probability of unicity. If you really want a unique ID you'll have to use an incremented integer.

That said there's a really small chance of having duplicate uniqids. Are you truncating the result of uniqid() in any way ?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top