Ticket #199 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Parent class method is not defined, depending on require() order / unserialize()

Reported by: blueyed Assigned to: somebody
Priority: critical Milestone: 0.9.6
Component: eAccelerator Version: 0.9.5
Keywords: Cc:

Description

test.php:

<?php

eaccelerator_clear();

require_once dirname(__FILE__).'/test_parent.class.php';
require_once dirname(__FILE__).'/test.class.php';

$Test = new Test();

test2.php

<?php
ini_set( 'unserialize_callback_func', 'unserialize_cb' );

function unserialize_cb($classname)
{
	require_once dirname(__FILE__).'/test.class.php';
}

$s = 'O:4:"Test":1:{s:4:"test";i:78701;}';

$o = unserialize($s);

var_dump($o);

$o->f();
?>

test.class.php:

<?php

require_once dirname(__FILE__).'/test_parent.class.php';

class Test extends Test_parent
{
	function Test()
	{
		$this->test = rand(0, 100000);

		parent::f();
	}
}

?>

test_parent.class.php:

<?php

class Test_parent
{
	function Test_parent()
	{
	}

	function f()
	{
		echo '<h2>f()</h2>';
	}
}

?>

Reproduce: 1. Call test.php. This will clear the cache. 2. Call test2.php.

Result:

object(Test)#1 (1) { test?=> int(78701) }

Fatal error: Call to undefined method Test::f() in /X/test2.php on line 16

Expected result:

object(Test)#1 (1) { test?=> int(78701) } f()

The expected result happens, if you clear the file cache and execute test2.php, without calling test.php first.

The error does not occur, if you swap the require statements in test.php and use

require_once dirname(__FILE__).'/test.class.php';
require_once dirname(__FILE__).'/test_parent.class.php';

instead of

require_once dirname(__FILE__).'/test_parent.class.php';
require_once dirname(__FILE__).'/test.class.php';

I've found this, while trying to reproduce ticket:183 and I think it's related at least.

eaccelerator r282, mod_php (PHP_5_2).

Change History

11/04/06 14:06:05 changed by bart

  • version set to 0.9.5.
  • milestone set to 0.9.6.

01/31/07 15:08:05 changed by bart

I think this bug is the same one as in #192 I was able to reproduce it for a while but after a clear gallery started working. I'm not able to reproduce this one.

01/31/07 15:12:05 changed by bart

I'm able to reproduce this. I forgot I turned of display_errors

02/01/07 14:00:30 changed by bart

The error is also reproducable without the deserialising. It's enough to do:

require_once dirname(__FILE__).'/test.class.php';
$o = new Test();
$o->f();

I'll have to add more debug code to localize the problem.

02/13/07 13:40:21 changed by bart

I think the problems seen in #236 and #192 are caused by this issue, although I'm not sure.

02/13/07 16:14:55 changed by bart

I've got new test cases that are even simpeler:

test.class.php:

<?php
class Test extends Test_parent {
    function __construct() {
        parent::f();
    }
}
?>

test_parent.class.php:

<?php
class Test_parent {
    function f() {
        echo '<h2>f()</h2>';
    }
}
?>

pre_test.php:

<?php
eaccelerator_clear();
require 'test_parent.class.php';
require 'test.class.php';
?>

do.php:

<?php
    require 'test.class.php';
    $o = new Test();
?>

Place them all in the same directory and run pre_test.php before do.php

02/13/07 17:57:25 changed by bart

test.class.php needs this to: require_once "test_parent.class.php";

I've noticed that 0.9.5 doesn't have this issue.

02/13/07 18:44:41 changed by bart

This bug is fixed in rev [294]

02/13/07 18:44:51 changed by bart

  • status changed from new to closed.
  • resolution set to fixed.