1

I'm running a Ubuntu 16.04 LTS VM with a LAMP setup, which has PHP 7.0 installed. When I run my code I get the following error: Class 'APCIterator' not found.

I made sure I have APCu installed and enabled:

$ sudo apt-get install php-apcu // install package
$ sudo phpenmod apcu // enable it

Is there anything I could do to resolve this problem (without editing the PHP code), or should I just switch back to Ubuntu 14 LTS and use PHP 5?

JasonK
  • 5,214
  • 9
  • 33
  • 61
  • see [this](http://stackoverflow.com/questions/34170434/how-install-apcu-as-php7-extension-on-debian) answer – DevDonkey May 23 '16 at 15:26
  • @DevDonkey I've tried that and APCu was installed correctly, but I think I need APC support (which I believe is deprecated since PHP7). The error `Class 'APCIterator' not found` remains. – JasonK May 24 '16 at 08:44

1 Answers1

4

PHP 7 removed backwards compatibility with the APC API. Unless you are using a backwards compatibility layer, the class is now called APCUIterator:

$ php -d 'apc.enable_cli=1' -d 'apc.enabled=1' -a
Interactive shell

php > var_dump(ini_get('apc.enabled'));
string(1) "1"
php > var_dump(ini_get('apc.enable_cli'));
string(1) "1"
php > var_dump(function_exists('apcu_fetch'));
bool(true)
php > var_dump(extension_loaded('apcu'));
bool(true)
php > var_dump(class_exists('\APCIterator'));
bool(false)
php > var_dump(class_exists('\APCUIterator'));
bool(true)

Note that the API between the classes has changed: the \APCIterator constructor took the cache to iterate over, while the \APCUIterator takes a pattern over which to iterate.

bishop
  • 37,830
  • 11
  • 104
  • 139