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

Merged
merged 15 commits into from
Jun 22, 2025
Merged

Implement "clone with" #185

merged 15 commits into from
Jun 22, 2025

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.

@thekid
Copy link
Member Author

thekid commented Jun 22, 2025

RFC has been accepted: https://externals.io/message/127588#127711

@thekid thekid merged commit 41f8a58 into master Jun 22, 2025
14 checks passed
@thekid thekid deleted the feature/clone-with branch June 22, 2025 07:45
@thekid
Copy link
Member Author

thekid commented Jun 22, 2025

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