php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56806 Cond. defined class does not inherit variables to child defined in sep. file
Submitted: 2006-01-27 12:18 UTC Modified: 2006-05-13 09:41 UTC
From: pecl dot 20 dot korkman at spamgourmet dot org Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5.1.1 OS: SUSE Linux 9.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 + 13 = ?
Subscribe to this entry?

 
 [2006-01-27 12:18 UTC] pecl dot 20 dot korkman at spamgourmet dot org
Description:
------------
APC 3.0.8, Apache 2

When require()ing a class in a seperate file that extends a prior defined class, APC caches the require()d file with all class variables from the parent. Dynamically defining the parent with different variable values will not change the variable values in the inheriting class. This also applies when conditionally require()ing the parent class from different files.

But functions are inherited fine. A workaround is to define the variable values in an inherited function, e.g. a constructor.

Reproduce code:
---------------
File "apc_start.php"

<?php
if (isset($_GET['new_engine'])) {
	class engine {
		public $engine_name = 'New engine.';
		function print_engine_function() {
			echo "New engine.";
		}
	}
} else {
	class engine {
		public $engine_name = 'Old engine.';
		function print_engine_function() {
			echo "Old engine.";
		}
	}
}
require('apc_include.inc.php');
$o = new user_script();
$o->print_engine_variable();
$o->print_engine_function();
echo "<p /><a href='".$_SERVER['PHP_SELF']."?new_engine'>New engine</a>";
echo "<br /><a href='".$_SERVER['PHP_SELF']."'>Old engine</a>";
?>

File "apc_include.inc.php"

<?php
class user_script extends engine {
	function print_engine_variable() {
		echo $this->engine_name;
	}
}
?>

Expected result:
----------------
Old engine.Old engine.
New engine.New engine.

Actual result:
--------------
Old engine.Old engine.
New engine.Old engine.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-25 05:23 UTC] gopalv82 at yahoo dot com
Half a patch for this is currently living in my INH_FIX branch code.

The problem is that APC currently uses real names of classes to insert into the EG(class_table), it has to use the mangled name if present for a dynamic class and let the opcode do the DECLARE_CLASS with the real name.

In other words, it's been worked up on :)
 [2006-03-14 01:30 UTC] gopalv82 at yahoo dot com
Patch @ http://t3.dotgnu.info/code/fix_6608.patch
 [2006-03-28 00:39 UTC] gopalv82 at yahoo dot com
Can you confirm fix from CVS ?
 [2006-05-13 09:41 UTC] gopalv82 at yahoo dot com
The bug's been fixed a while ago, please see patch. 

Closing without confirmation from reporter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 00:01:34 2024 UTC