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 )

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!