ID:               41961
 User updated by:  robin_fernandes at uk dot ibm dot com
 Reported By:      robin_fernandes at uk dot ibm dot com
 Status:           Assigned
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5CVS-2007-07-11 (snap)
 Assigned To:      dmitry
 New Comment:

Sorry - step 2 in the description should read:
"2. An unrelated class has a *private* method of the same name."


Previous Comments:
------------------------------------------------------------------------

[2007-07-11 13:06:30] robin_fernandes at uk dot ibm dot com

Below is a _suggested_ fix to zend_object_handlers.c based on snap
php5.2-200707111030. I have only tested on Linux using 'make test'.

Note that I am not highly familiar with the Zend Engine internals, so I
could have overlooked a side effect or a better solution.

--- php5.2-theirs/Zend/zend_object_handlers.c 2007-03-23
17:30:59.000000000 +0000
+++ php5.2-mine/Zend/zend_object_handlers.c 2007-07-11
13:19:43.000000000 +0100
@@ -800,7 +800,7 @@
   /* Ensure that we haven't overridden a private function and end up
calling
    * the overriding public function...
    */
-  if (EG(scope) && fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
+  if (EG(scope) && is_derived_class(fbc->common.scope, EG(scope)) &&
fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
    zend_function *priv_fbc;

    if (zend_hash_find(&EG(scope)->function_table, lc_method_name,
method_len+1, (void **) &priv_fbc)==SUCCESS

------------------------------------------------------------------------

[2007-07-11 13:01:50] robin_fernandes at uk dot ibm dot com

Description:
------------
The wrong method is invoked if the following conditions are met:
1. A class has a public method that overrides/hides private method from
its parent. 
2. An unrelated class has a public method of the same name.
3. The overriding method is invoked from within the unrelated class.

The unrelated class's method will be called instead of the overriding
method. See the testcase below for an example.

Reproduce code:
---------------
The testcase is over 20 lines, but can be found here:
http://www.nomorepasting.com/getpaste.php?pasteid=1270

Expected result:
----------------
Called public ChildClass::secret() on an instance of: ChildClass

Actual result:
--------------
Called private X::secret() on an instance of: ChildClass


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41961&edit=1

Reply via email to