Mantis - Quercus
Viewing Issue Advanced Details
2876 major always 08-28-08 10:18 08-28-08 19:38
koreth  
nam  
high  
closed 3.2.1  
fixed  
none    
none 3.2.1  
0002876: APC-cached objects' classes are assigned at store, not at fetch
Here's test1.php, which unserializes an instance of an undefined class and stashes it in APC:

<?php
$foo = unserialize('O:3:"Foo":1:{s:3:"bar";i:1;}');
apc_store('test', $foo);

And here's test2.php, which defines the class and pulls the object from APC:

<?php
class Foo {
  public $bar;
}

$foo = apc_fetch('test');
if ($foo instanceof Foo) {
  print "it's a Foo\n";
} else {
  print_r($foo);
}

In plain PHP, fetching test1.php then test2.php gets you "it's a Foo". In Quercus, you get the print_r of the incomplete-class-name object.

We have an "initialize APC" script that reads a couple megabytes worth of data and stashes it into APC; that script doesn't need to have all the class declarations loaded in regular PHP. In Quercus it breaks in a bunch of places because the objects aren't of the expected types when they're pulled from APC.

For our purposes it's sufficient to just fix this for the case of an object whose class was undefined at the time it was stored in APC (but is defined at fetch time) and I think that's probably the most common case in general. But I suppose there could also be more obscure cases where you have two classes of the same name but with different methods that you want to be able to instantiate from the same APC entries. Not good programming practice, of course, but it would work fine in vanilla PHP.

Notes
(0003366)
nam   
08-28-08 19:38   
php/4209
php/420a
php/420b

On apc_fetch() call, PHP will attempt to inject the currently available classes into all fetched objects. Quercus now follows this pattern.