if ( ! isset(static::$instances[$name]))which would indicate $name contains something you can't use as an array index. If $name isn't passed to instance() manually by you, it will be fetched from the config like so:
$name = \Config::get('db.active');which means you will have to check your db.php config file(s) to see if you have misconfigured something. the 'active' value should be a string and should match one of the defined database configurations.
class C extends D {}; class B extends C {}; class A extends B {}; $var = new A();then "$var instanceOf D" will return true, as by extension $var is an instance of class D. Same here, all database connection object are instances of Database_Connection, as all connectiondrivers extend that class. Again, this is not the source of your problem. If you say that $name is "an instance of", you mean it's a object? If so, that would prove my point, as you can't use an object as an array index, which is the exact error message. Again, $name should be a string, containing the name of your instance, which should be equal to the name used in your db.php to configure the connection.
which has nothing to do with APC, but with the fact that you use a value as an array index that can't be used as an index. Like for example an object. I've asked you what is passed as $name, to which you repliedErrorException [ Warning ]: Illegal offset type in isset or empty
. So I repeat: $name should be a string with the name of the database instance. And not the instance itself! Fix your code and your problem will be fixed.$name is an instance of Fuel\Core\Database_Connection
// get the default database instance $db = \Database_Connection::instance(); // and now create the error \Database_Connection::instance($db);and there you have your exact error. No APC involved. I have looked at your code. Fix it. You should NEVER call \Fuel\Core classes directly. NEVER. Call them from the global namespace, as documented. Not a single piece of documentation will suggest you do use the \Fuel\Core namespace. If I change it to
<?php class Controller_Apc extends \Fuel\Core\Controller_Rest { public function action_first() { apc_clear_cache(); $test = new Model_Apc(); $str = $test->first(); $this->response($str); } public function action_second() { $test = new Model_Apc(); $str = $test->second(); $this->response($str); } } class Model_Apc extends \Fuel\Core\Model { function first() { $db = \DB::query('SELECT * FROM articles'); $res = $db->execute(); $str = ''; foreach ($res as $r) { $str .= $r['name'] . "\n"; } return $str; } function second() { $db = \Database_Connection::instance('book'); $res = \DB::query('SELECT * FROM articles')->execute($db); $str = ''; foreach ($res as $r) { $str .= $r['id'] . "\n"; } return $str; } }it runs fine, even with APC switched on.
It looks like you're new here. If you want to get involved, click one of these buttons!