Skip to content

fix(class): Implement clone behavior#685

Merged
ptondereau merged 1 commit intomasterfrom
fix/cloning-class
Mar 4, 2026
Merged

fix(class): Implement clone behavior#685
ptondereau merged 1 commit intomasterfrom
fix/cloning-class

Conversation

@ptondereau
Copy link
Member

Description

Fix #683

Note: our object_properties_init initializes the properties table with default values, then zend_objects_clone_members dtors those defaults and copies from the original. PHP's default sets ZVAL_UNDEF first instead. Both work, but ours does a small unnecessary alloc+free cycle for each default property.

In the end, this matches the PHP cloning contract: properties are shallow-copied, __clone() is invoked. The Rust data is cloned via Clone::clone(), which is the correct equivalent since the Rust struct owns its data independently.

@ptondereau ptondereau force-pushed the fix/cloning-class branch 2 times, most recently from d9ce811 to bb55264 Compare March 3, 2026 20:02
@ptondereau ptondereau merged commit cddb647 into master Mar 4, 2026
65 checks passed
@ptondereau ptondereau deleted the fix/cloning-class branch March 4, 2026 15:07
@Xenira Xenira mentioned this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native PHP clone operator leaves internal Rust struct uninitialized, causing "Invalid value given for argument" on any subsequent use

1 participant