php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70990 private __clone in inheritance situation
Submitted: 2015-11-28 17:31 UTC Modified: 2015-11-29 15:31 UTC
From: remyfox at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.16 OS: Windows
Private report: No CVE-ID: None
 [2015-11-28 17:31 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-29 15:31 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2015-11-29 15:31 UTC] ab@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC