php-jsondb icon indicating copy to clipboard operation
php-jsondb copied to clipboard

Add unique ID

Open lenivene opened this issue 5 years ago • 5 comments

Generate a unique ID when insert value

lenivene avatar Oct 21 '19 03:10 lenivene

According to the official php documentation at php.net the function does not guarantee uniqueness.

I suppose this won't be a problem when running in development and demonstration environment but it's a limitation worth knowing.

kungknut avatar Jan 25 '20 09:01 kungknut

This is why I have not merged the pull yet. Finding a right approach, haven't gotten enough time to think it through

On Sat, 25 Jan 2020, 10:12 Philip Lundqvist, [email protected] wrote:

According to the official php documentation at php.net https://www.php.net/manual/en/function.uniqid.php#refsect1-function.uniqid-returnvalues the function does not guarantee uniqueness.

I suppose this won't be a problem when running in development and demonstration environment but it's a limitation worth knowing.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/donjajo/php-jsondb/pull/11?email_source=notifications&email_token=AC4YZGDE4M54VF7FWTZTM3DQ7P665A5CNFSM4JCXTCC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ4YRMY#issuecomment-578390195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4YZGCZBXEDANU27RQD7TTQ7P665ANCNFSM4JCXTCCQ .

donjajo avatar Jan 25 '20 09:01 donjajo

What's your thoughts about adding dependencies and using UUIDv4?

If you can accept adding ramsey/uuid as a dependency you could do something like this to generate a UUIDv4 string instead of uniqid();

Uuid::uuid4()->toString()

kungknut avatar Jan 25 '20 09:01 kungknut

This is why I have not merged the pull yet. Finding a right approach, haven't gotten enough time to think it through On Sat, 25 Jan 2020, 10:12 Philip Lundqvist, @.***> wrote: According to the official php documentation at php.net https://www.php.net/manual/en/function.uniqid.php#refsect1-function.uniqid-returnvalues the function does not guarantee uniqueness. I suppose this won't be a problem when running in development and demonstration environment but it's a limitation worth knowing. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#11?email_source=notifications&email_token=AC4YZGDE4M54VF7FWTZTM3DQ7P665A5CNFSM4JCXTCC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ4YRMY#issuecomment-578390195>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4YZGCZBXEDANU27RQD7TTQ7P665ANCNFSM4JCXTCCQ .

What about using the function with time and options more_entropy: uniqid(time(), true);.

basteyy avatar Mar 16 '20 19:03 basteyy

Or you can include paragonie/random_compat as a dependency and use random_int and such PHP7 functions even on PHP5 to get unique random values.

aik099 avatar Nov 30 '22 07:11 aik099