dousi0144 2013-02-20 20:11
浏览 13
已采纳

命名空间和APC失败

I'm trying to use APC with PHP. I've copied the code from the PHP manual for storing arrays in APC; and it works great, as I would expect.

My problem arises when I introduce a namespace when it fails.

<?php
namespace tester;

$objs = array();
$objs[] = "123";
$objs[] = "123";
$objs[] = "123";

apc_store('tester:objs', new ArrayObject($objs),60);
$tmp = apc_fetch('tester:objs');
print_r($tmp -> getArrayCopy());
exit;
  • 写回答

1条回答 默认 最新

  • doulai8128 2013-02-20 21:36
    关注

    Ahhhhh! I knew it would be something simple! I simple forgot to declare ArrayObject as a global namespace class. Adding a slash in front of ArrayObject worked. Silly me! :(

    Working code:

    <?php
    namespace tester;
    
    $objs = array();
    $objs[] = "123";
    $objs[] = "123";
    $objs[] = "123";
    
    apc_store('tester:objs', new \ArrayObject($objs),60);
    $tmp = apc_fetch('tester:objs');
    print_r($tmp -> getArrayCopy());
    exit;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!