|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-26 14:20 UTC] felix9x at yahoo dot com
Description:
------------
My codebase worked fine with APC 3.0.19 & php 5.2.8.
After upgrading to php 5.2.10 with either APC 3.0.19 or 3.1.2 I get this error:
Fatal Error: Class xxxx Not found in file /something/file.php
Using default settings for APC.
Reproduce code:
---------------
Basically the code lookes like this:
classfile.php
---------------
class X {
function foo() {
$v = new Y();
}
}
class Y {
}
tester.php
include( __FILE__ . '../classfile.php' );
$x = new X();
--
Get error:
Class Y not found in
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 15:00:02 2025 UTC |
Very sorry to flood the page but this is a simpler example (all in one script) with different messages that may be more helpful. And again, this is only with APC enabled. [php] <?php class Session { public static function handler_open($i_savepath, $i_sessname) { return DB::connected(); } public static function handler_close() { return DB::close(); } public static function handler_read($i_sid) { return DB::read($i_sid); } public static function handler_write($i_sid, $i_data) { return DB::save($i_sid, $i_data); } public static function handler_destroy($i_sid) { return TRUE; } public static function handler_gc($i_maxlifetime) { return TRUE; } public static function start() { session_set_save_handler( array('Session', 'handler_open'), array('Session', 'handler_close'), array('Session', 'handler_read'), array('Session', 'handler_write'), array('Session', 'handler_destroy'), array('Session', 'handler_gc') ); session_start(); } } class DB { public static function connected() { return TRUE; } public static function close() { return TRUE; } public static function read($i_sid) { return TRUE; } public static function save($i_sid, $i_data) { return TRUE; } } Session::start(); die('foo'); [/php] [output] foo Warning: Invalid callback Session::handler_write, class 'Session' not found in Unknown on line 0 Warning: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct () in Unknown on line 0 Warning: Invalid callback Session::handler_close, class 'Session' not found in Unknown on line 0i confirm that this error occurs on php 5.2.11 and apc 3.0.19 php 5.3.1 and apc 3.1.3p1 but php 5.2.10 and apc 3.0.19 works fine. here is the test case: <?php class SessionHandler { public static function open($session_path, $session_name){ return true; } public static function close(){ return true; } public static function read($session_id){ return null; } public static function write($session_id, $session_data){ return true; } public static function destroy($session_id){ return true; } public static function gc($maxlifetime){ return true; } } session_module_name('user'); session_set_save_handler( 'SessionHandler::open' , 'SessionHandler::close' , 'SessionHandler::read' , 'SessionHandler::write' , 'SessionHandler::destroy', 'SessionHandler::gc' ); echo session_start(); ?> --first run result 1 --second and other run's 1 Warning: Invalid callback SessionHandler::write, class 'SessionHandler' not found in Unknown on line 0 Warning: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0 Warning: Invalid callback SessionHandler::close, class 'SessionHandler' not found in Unknown on line 0 (of you should run this via httpd and mod_php) this code fails only if callback functions defined as class static members. folowwing code works fine: <?php class SessionHandler { public function open($session_path, $session_name){ return true; } public function close(){ return true; } public function read($session_id){ return null; } public function write($session_id, $session_data){ return true; } public function destroy($session_id){ return true; } public function gc($maxlifetime){ return true; } } $s = new SessionHandler(); session_module_name('user'); session_set_save_handler( array($s,'open') , array($s,'close') , array($s,'read') , array($s,'write') , array($s,'destroy'), array($s,'gc' )); echo session_start(); ?> if you need more info I can run strace or run httpd via gdb.Hi, Sorry to clutter the bug, but I have an even simpler way to reproduce this bug - no custom session handlers are required, just any static reference to a class while serializing the session. As with previous examples, calling session_write_close() rather than leaving PHP to write the session automatically causes it to work fine. It also works normally the first time APC compiles it after an edit or restart. Source: <?php class Example { private static $f = ' [Static Var Exists] '; public function __sleep() { echo ' [Class ' . __CLASS__ . ( class_exists(__CLASS__) ? ' exists' : ' does not exist' ) . '] '; echo self::$f; return array(); } } session_start(); $_SESSION['x'] = new Example('hello'); echo 'Output something, then leave PHP to write session... '; ?> Output when run from APC cache (PHP 5.2.17, APC 3.1.6): Output something, then leave PHP to write session... [Class Example does not exist] Fatal error: Access to undeclared static property: Example::$f in /home/rowanc/development/cwt/sites/JTATravelGroup/JTATrade/trunk/htdocs/static.php on line 12An easy way to apply rasmus fix to your scripts if you don't know when or if they're exiting is registering a shutdown function: register_shutdown_function("session_write_close");<?php // All in a single file, no includes, no requires. ini_set('display_errors', 1); error_reporting(-1); // Work-around as suggested by cvives at infoactiu dot com and others fixes it // register_shutdown_function('session_write_close'); class Inner { } class SessionHandler { public function __construct() { var_dump(class_exists('Inner')); } public function method() { var_dump(class_exists('Inner')); return true; } } $handler = new SessionHandler(); session_set_save_handler( array($handler, 'method'), // open array($handler, 'method'), // close array($handler, 'method'), // read array($handler, 'method'), // write array($handler, 'method'), // destroy array($handler, 'method') // gc ); session_start(); ?> Actual results: On the 2nd+ reload, prints a few "true" and then a few "false" class "Inner" stops existing during shutdown Expected results: print all "true" a defined class should not vanish OS: CentOS 6.2 - x86_64 PHP: 5.3.3 APC: 3.1.3p1 versions installed via YUM Updated APC to 3.1.10-beta via PECL and got the same results