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
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:
7 + 36 = ?
Subscribe to this entry?

 
 [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: Sun May 05 07:01:32 2024 UTC