File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -609,5 +609,10 @@ public function __clone()
609609 foreach ($ this ->attributes as &$ attribute ) {
610610 $ attribute = clone $ attribute ;
611611 }
612+
613+ // Reset callbacks to avoid memory leaks
614+ $ this ->callbacks = [];
615+ $ this ->newCallbacks = [];
616+ $ this ->setterCallbacks = [];
612617 }
613618}
Original file line number Diff line number Diff line change @@ -668,4 +668,18 @@ public function testRenderThrowsIfLegacyAndNewAttributeCallbacksConflict(): void
668668
669669 $ attributes ->render ();
670670 }
671+
672+ /**
673+ * @depends testRenderHandlesCallbackResultsCorrectly
674+ */
675+ public function testCallbacksAreResetUponClone (): void
676+ {
677+ $ attributes = (new Attributes ())
678+ ->setCallback ('callback ' , fn () => 'foo ' )
679+ ->registerAttributeCallback ('callback2 ' , fn () => 'bar ' );
680+
681+ $ clone = clone $ attributes ;
682+
683+ $ this ->assertSame ('' , $ clone ->render ());
684+ }
671685}
You can’t perform that action at this time.
0 commit comments