Req #67409 [Com]: Clone arguments
| From: | phpmpan at mpan dot pl | Date: | Wed, 11 Jun 2014 03:36:51 +0000 |
| Subject: | Req #67409 [Com]: Clone arguments | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186146@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67409&edit=1
ID: 67409
Comment by: phpmpan at mpan dot pl
Reported by: flip101 at gmail dot com
Summary: Clone arguments
Status: Open
Type: Feature/Change Request
Package: Class/Object related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
clone creates a clone of an object. That is: an object equivalent to the original one.
If you want to create a method with a different contract then... create a method with a different
contract.
Previous Comments:
------------------------------------------------------------------------
[2014-06-10 10:33:01] flip101 at gmail dot com
To clarify "The solution to the second use case" --> the situation right now without
this feature.
in case __invoke() is implemented it is not called. Same behaviour as __construct(). See: http://codepad.viper-7.com/eBL3WY
------------------------------------------------------------------------
[2014-06-10 10:12:44] flip101 at gmail dot com
Description:
------------
It would be nice if the clone function could take arguments. Some scenario's where this would
be useful:
1. The type of cloning, like deep-cloning (see given example)
2. Initialize with external values, similar to a constructor
The solution to the second use case would be to clone first and then set the property right on the
clone. Which would need a public property, a setter or a hydration method (like reflection).
Something that is sometimes not desired.
Test script:
---------------
<?php
class Bar { }
class Foo {
public function __construct() {
$this->bar = new Bar;
}
public function __clone($deep = false) {
if ($deep) {
$this->bar = clone $this->bar;
}
}
}
$a = new Foo;
$b = clone $a(true);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67409&edit=1