php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48686 Cyclic inclusion of classes
Submitted: 2009-06-25 09:01 UTC Modified: 2009-12-08 01:00 UTC
Votes:17
Avg. Score:4.8 ± 0.5
Reproduced:14 of 15 (93.3%)
Same Version:9 (64.3%)
Same OS:10 (71.4%)
From: codextasy at gmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.2.10 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: codextasy at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-25 10:06 UTC] davide dot ferrari at atrapalo dot com
Same grave bug here! But here it happens only when APC (3.0.19) is enabled. Can the OP confirm it happens only with APC as well?
 [2009-06-25 10:31 UTC] codextasy at gmail dot com
I can reproduce the bug with or without APC installed/enabled.
 [2009-07-06 08:26 UTC] pietro dot baldassarri at unibo dot it
Same problem here (Gentoo Linux PHP 5.2.10).
This bug seems some way related to this http://bugs.php.net/bug.php?id=48787
 [2009-11-12 14:41 UTC] aaron at xavisys dot com
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();
 [2009-11-30 19:32 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-12-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC