|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-25 09:01 UTC] codextasy at gmail dot com
Description:
------------
There is a bug with cyclic inclusion of files with class definition.
There are three classes - A, B, C - each placed in a separate file - A.php, B.php, C.php - all in the same directory.
B is a derived class of A, C is a derived of B.
So, B.php includes A.php (using require_once), C.php includes B.php.
A.php contains both class A and function f(), which is subsequently called. f() includes 'C.php'.
When trying to request B.php (or include it from another file) I get Fatal error: Class 'B' not found C.php on line 4.
Reproduce code:
---------------
Three files here:
--------[ A.php ]--------
<?
class A {}
function f()
{
include 'C.php';
}
f();
?>
--------[ B.php ]--------
<?
require_once 'A.php';
class B extends A {}
?>
--------[ C.php ]--------
<?
require_once 'B.php';
class C extends B {}
?>
Expected result:
----------------
No error when requesting or including B.php.
Actual result:
--------------
Fatal error: Class 'B' not found in /srv/www/test/C.php on line 4
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
I'm having the same issue. My problem is that I upgraded from PHP 5.2.9 to 5.2.11 and set up APC at the same time. The problem actually affected my custom session handler. After finding this ticket I disabled APC and restarted apache, but the problem persists. My code to recreate: session.class.php ------------------ <?php /** * These are our session handler functions */ class Session { /** * Open a session * * @return bool true */ public static function ses_open() { return true; } /** * Closes the session, after cleaning up. * * @return bool true */ public static function ses_close() { self::ses_clean(ini_get('session.gc_maxlifetime')); return true; } /** * Reads the data from the session. * * @param string $session_id * @return unknown */ public static function ses_read($session_id) { $db = db::get_instance(); $q = "SELECT `data` FROM `sessions` WHERE `id`=".quote_smart($session_id); if (($r = $db->query($q)) && $r->num_rows > 0) { $i = $r->fetch_object(); return $i->data; } return false; } /** * Writes the session * * @param string $session_id * @param string $data - serialized version of $_SESSION * @return unknown */ public static function ses_write($session_id, $data) { /** * I guess that our database connection is closed before this runs, but the * static variable is not reset. We run the destroy instance first, so that * the singleton knows to create a new instance */ db::destroy_instance(); $db = db::get_instance(); $uid = (isset($_SESSION['uid']))? $_SESSION['uid']:''; $q = "REPLACE INTO `sessions` (`id`, `uid`, `ip`, `data`) VALUES (".quote_smart($session_id, $uid, $_SERVER['REMOTE_ADDR'], $data).')'; return $db->query($q); } /** * Destroys the session, and clears our 'remember me' cookie, so we can use this * to log a user out * * * @param string $session_id * @return bool */ public static function ses_destroy($session_id) { $db = db::get_instance(); $q = "DELETE FROM `sessions` WHERE `id`=".quote_smart($session_id); if(isset($_COOKIE['user'])){ setcookie("ezd_user", '', time()-(60*60*24*7), '/', ''); //60*60*24*7=secs*mins*hrs*days=7days } return $db->query($q); } /** * Cleans up (removes) old sessions * * @param int $max - How old "old" data is (in seconds) * @return bool */ public static function ses_clean($max) { $db = db::get_instance(); $q = "DELETE FROM `sessions` WHERE `access` < NOW() - INTERVAL {$max} SECOND"; return $db->query($q); } } test.php ----------- /** * Starts a session. Since we need to do this in more than one place, this * function sets the session name and handler, then starts it. */ function start_session() { require_once('session.class.php'); session_name('EZD_ID'); /* session_set_save_handler( array('Session','ses_open'), array('Session','ses_close'), array('Session','ses_read'), array('Session','ses_write'), array('Session','ses_destroy'), array('Session','ses_clean')); */ session_start(); } start_session();