Skip to content

Implement "clone with" #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Implement "clone with" #185

wants to merge 14 commits into from

Conversation

thekid
Copy link
Member

@thekid thekid commented Apr 21, 2025

class Person {
  public function __construct(public string $name) { }
}

$person= new Person('Test');
$clone= clone($person, ['name' => 'Clone of Test']);

Implementation status

  • Clone with syntax
  • Clone first-class callable syntax clone(...)
  • Clone with unpacking (e.g. clone(...[$object, $properties]))
  • Error compatibility for visibility mismatches: Could be done via reflection but with a significant performance cost
  • Clone as callable (e.g. array_map('clone', $array) - not feasible

See also:

@thekid
Copy link
Member Author

thekid commented Jun 10, 2025

Vote started on June 4th, 2025: https://externals.io/message/127588

@@ -19,7 +19,7 @@
* @see https://wiki.php.net/rfc#php_85
*/
class PHP85 extends PHP {
use RewriteBlockLambdaExpressions;
use RewriteBlockLambdaExpressions, RewriteCallableClone, RewriteCloneWith; // TODO: Remove once PR is merged!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the PR in php-src is merged, we can drop these and natively emit clone expressions as function calls with their arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant