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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: remyfox at hotmail dot com
New email:
PHP Version: OS:

 

 [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: Sat May 04 16:01:31 2024 UTC