php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38079 __copy magic method to increase backwards compatibility
Submitted: 2006-07-12 13:34 UTC Modified: 2018-05-05 18:14 UTC
From: wickedfather at hotmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.1.5CVS OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wickedfather at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-07-12 13:34 UTC] wickedfather at hotmail dot com
Description:
------------
An extra magic method that works in the same was as __clone but is called when an object is assigned in the normal way.  Code earlier that php5 could be fixed in one place by adding a single method to a class rather than having to find every $obj1 = $obj2 line in your scripts.

Reproduce code:
---------------
<?php
class MyClass
{
	public function __copy
	{
		echo 'I want to return a copy, not a reference, like in olden days';
		return clone($this);
	}
}

$obj1 = new MyClass;

$obj2 = $obj1;
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-05 18:14 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2018-05-05 18:14 UTC] requinix@php.net
Old request is old.

PHP 5's OOP rewrite is long in the past now and its revised treatment of object instances is the norm.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC