doucuo8618 2012-06-02 08:44
浏览 79
已采纳

uuid-php.x86_64 uuid_create()“参数未通过引用传递”问题

uuid_create requires the parameter to be passed by reference.

uuid_create(&$foo);

The problem is that this will produce error:

Message:    Call-time pass-by-reference has been deprecated

Is the PHP extension uuid-php.x86_64 outdated? It is not "compatible" with the PHP 5. What are the alternatives?

Just wantend to highlight that this is not a duplicate.

$foo    = NULL;

uuid_create($foo);

Will produce:

Type:       Run-time warnings (non-fatal error).
Message:    uuid_create(): uuid_create: parameter wasn't passed by reference
  • 写回答

1条回答 默认 最新

  • dqdtgiw4736 2012-06-02 09:00
    关注

    PHP does not have a method uuid_create and it's not mentioned in the docs so if it comes from an extension it's most likely not an official one and probably outdated. The fact that the function expects an out parameter instead of returning the value is already a pretty obvious sign that the function is rather bad.

    However, writing PHP code to generate an uuid4 is pretty easy as it uses random values for all its fields, i.e. you do not need to access system-specific things such a the MAC address:

    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)
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c