JasonK
JasonK

Reputation: 5294

APCIterator class not found for PHP7

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?

Upvotes: 1

Views: 2197

Answers (1)

bishop
bishop

Reputation: 39474

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.

Upvotes: 4

Related Questions