php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34908 uniqid() produces too long strings on cygwin
Submitted: 2005-10-18 15:29 UTC Modified: 2005-10-20 16:43 UTC
From: nohn@php.net Assigned:
Status: Closed Package: Strings related
PHP Version: 5.1.0RC3 OS: Cygwin
Private report: No CVE-ID: None
 [2005-10-18 15:29 UTC] nohn@php.net
Description:
------------
Taking the regression test tests/strings/001.phpt, uniqid behaves different on Cygwin than specified in the manual.

This may be related to #2201, but the very same test acts on Linux as expected.

Reproduce code:
---------------
<?php
echo "Testing uniqid: ";
$str = "prefix";
$ui1 = uniqid($str);
$ui2 = uniqid($str);
if (strlen($ui1) == strlen($ui2) && strlen($ui1) == 19 && $ui1 != $ui2) {
        echo("passed\n");
} else {
        echo("failed!\n");
}

var_dump(strlen($ui1));
var_dump(strlen($ui2));
var_dump($ui1);
var_dump($ui2);
?>


Expected result:
----------------
$ php  ~/test.php 
Testing uniqid: failed!
int(29)
int(29)
string(29) "prefix4354f7719641d8"
string(29) "prefix4354f7719641d3"

Actual result:
--------------
$ php  ~/test.php 
Testing uniqid: failed!
int(29)
int(29)
string(29) "prefix4354f7719641d8.40924743"
string(29) "prefix4354f7719641d3.17144927"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-19 15:40 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

On Cygwin systems to ensure a trully unique id the more_entropy is enabled by default, which causes another 9 characters to appear at the end. This is a not a bug.
 [2005-10-19 19:38 UTC] nohn@php.net
Reopening.

In that case, tests/strings/001.phpt needs to behave different on Cygwin than on other systems.
 [2005-10-19 23:17 UTC] tony2001@php.net
Do you know of any way to detect if PHP is running on Cygwin from PHP itself?
 [2005-10-20 10:33 UTC] nohn@php.net
Tony:
-----
You don't need to find that out. Either set it always to true or always to false:

$ui1 = uniqid($str, false);
$ui2 = uniqid($str, false);

Of course you could also use php_uname() for that. Cygwin identifies as Cygwin, so there is no problem here.

Ilia:
-----
That behaviour is not documented on http://de2.php.net/uniqid
 [2005-10-20 11:16 UTC] tony2001@php.net
So make a patch then and make sure that it works for you on Cygwin.
I don't have Cygwin anywhere and I'm sure Ilia doesn't have it either.
 [2005-10-20 12:23 UTC] nohn@php.net
184c185,192
< if (strlen($ui1) == strlen($ui2) && strlen($ui1) == 19 && $ui1 != $ui2) {
---
> 
> if (strtoupper(substr(php_uname(), 0, 6)) === 'CYGWIN') {
>   $expected_length = 29;
> } else {
>   $expected_length = 19;
> }
> 
> if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $expected_length && $ui1 != $ui2) {


 [2005-10-20 16:43 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC