Bug #70990 [Opn->Nab]: private __clone in inheritance situation
Edit report at https://bugs.php.net/bug.php?id=70990&edit=1
ID: 70990
Updated by: ab@php.net
Reported by: remyfox at hotmail dot com
Summary: private __clone in inheritance situation
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 5.6.16
Block user comment: N
Private report: N
New Comment:
Thanks for the report. This has nothing to do with clone but with the visibility. A private
method/property is always inaccessible in an inheriting class.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-11-28 17:31:19] remyfox at hotmail dot com
Description:
------------
Creating a private method __clone, while cloning $this, where $this is an instance of a child class
of self, will set the context of the caller to $this, instead of self, which is somewhat unusual,
given that calling a private method from self is otherwise succesful.
Making the method protected solves the issue, but makes cloning by other classes in the hierarchy
possible too, which may be undesirable.
Test script:
---------------
This is an example:
http://pastebin.com/5z4xrQdR
Expected result:
----------------
four times the string "I occurred"
Actual result:
--------------
three times the string "I occurred" and an error message
Fatal error: Call to private F::__clone() from context 'E' in __FILE__ on line 48
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70990&edit=1
Thread (2 messages)