dpylt7626401 2014-12-10 03:22
浏览 71
已采纳

PHP APCu:apc_fetch()是否传递引用?

Or does it create a copy of whatever is stored and add this to the script's local memory?

I have a case in which I'm deciding whether to use APCu to cache a seldom changed variable (once a month), or just to re-declare that variable at run time (optimised with OpCache), and upload a new PHP script whenever I change it.

  • 写回答

1条回答 默认 最新

  • dqyuipw44576 2014-12-10 03:52
    关注

    As @zerkmes mentions in his comment, apc_fetch passing references should not be the expected behavior, due to each script having a fixed block of allocated memory.

    I've found an experiment (posted by aktharmiah at gmail dot com) in the comments section of: http://php.net/manual/en/function.apc-fetch.php which confirms this:

    class foo{
        public $bar;    
    }
    
    apc_add("foo",  new foo());
    
    $fooGot    =    apc_fetch("foo");
    $fooGot->bar = 1234;    
    
    print_r(apc_fetch("foo"));
    echo '<br>';
    print_r($fooGot);
    

    Indeed prints:

    foo Object ( [bar] => )

    foo Object ( [bar] => 1234 )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分