Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

5.4: Cannot access COM_CREATE_GUID #591

Closed
jcookems opened this Issue Jul 24, 2012 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

jcookems commented Jul 24, 2012

When I upgraded to PHP 5.4, the unit tests failed because PHP could not access the COM_CREATE_GUID function. Instead of trying to figure out how to get it re-enabled, we should remove the call to that function, as pointed out in #465.

Removed Windows specific code (com_create_guid()) to make tests run on linux

I extracted @beberlei's getGuid method, made a few minor changes:

/**
 * Returns a string representation of a version 4 GUID, which uses random
 * numbers.There are 6 reserved bits, and the GUIDs have this format:
 *     xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx
 * where 'x' is a hexadecimal digit, 0-9a-f.
 *
 * See http://tools.ietf.org/html/rfc4122 for more information.
 *
 * Note: This function is available on all platforms, while the
 * com_create_guid() is only available for Windows.
 *
 * @return string A new GUID.
 */
public static function getGuid() {
    return sprintf('%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x',
        mt_rand(0, 65535),
        mt_rand(0, 65535),        // 32 bits for "time_low"
        mt_rand(0, 65535),        // 16 bits for "time_mid"
        mt_rand(0, 4096) + 16384, // 16 bits for "time_hi_and_version", with
                                  // the most significant 4 bits being 0100
                                  // to indicate randomly generated version
        mt_rand(0, 64) + 128,     // 8 bits  for "clock_seq_hi", with
                                  // the most significant 2 bits being 10,
                                  // required by version 4 GUIDs.
        mt_rand(0, 256),          // 8 bits  for "clock_seq_low"
        mt_rand(0, 65535),        // 16 bits for "node 0" and "node 1"
        mt_rand(0, 65535),        // 16 bits for "node 2" and "node 3"
        mt_rand(0, 65535)         // 16 bits for "node 4" and "node 5"
    );

Then, in MimeReaderWriter,

-    $batchGuid     = strtolower(trim(com_create_guid(), '{}'));
+    $batchGuid     = Utilities::getGuid();
     $batchId       = sprintf('batch_%s', $batchGuid);
     $contentType1  = array('content_type' => "$mimeType");
-    $changeSetGuid = strtolower(trim(com_create_guid(), '{}'));
+    $changeSetGuid = Utilities::getGuid();
Contributor

ogail commented Jul 24, 2012

yup we have to do this as this will stop our code from working on other platforms than Windows

ogail pushed a commit to ogail/azure-sdk-for-php that referenced this issue Jul 25, 2012

Merge pull request #25 from ogail/dev
Fix #591

Code review: gcheng

@ogail ogail closed this in a8435bc Aug 17, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment