uuid_create
要求参数通过引用传递。
uuid_create(&$foo);
问题是这会产生错误:
Message: Call-time pass-by-reference has been deprecated
PHP扩展程序uuid-php.x86_64
是否已过时?它与PHP 5“不兼容”。有哪些替代方案?
只是想强调这不是重复。
$foo = NULL;
uuid_create($foo);
将产生:
Type: Run-time warnings (non-fatal error).
Message: uuid_create(): uuid_create: parameter wasn't passed by reference
答案 0 :(得分:3)
PHP没有方法uuid_create
,并且在文档中没有提及它,所以如果它来自扩展,它很可能不是官方的,可能已经过时了。函数需要out参数而不是返回值这一事实已经是一个非常明显的迹象,表明函数相当糟糕。
但是,编写PHP代码来生成uuid4非常简单,因为它为所有字段使用随机值,即您不需要访问特定于系统的内容,例如MAC地址:
function uuid4() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}