2013-02-20 83 views
0

我試圖在PHP中使用APC。我已經複製了PHP manual for storing arrays in APC的代碼;正如我所期望的那樣,它工作得很好。命名空間和APC失敗

當我在引入命名空間失敗時出現問題。

<?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; 

回答

0

Ahhhhh!我知道這會很簡單!我簡單地忘記將ArrayObject聲明爲全局命名空間類。在ArrayObject前面添加一個斜線。傻我! :(

工作代碼:

<?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;