PHP

clone & __clone

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

$b = $a; s'kopjon objektin — të dyja tregojnë te i njëjti. clone $a krijon kopje të cekët, dhe me __clone() mund të kopjosh edhe objektet brenda.

EnglishEN

$b = $a; doesn't copy the object — both point to the same one. clone $a creates a shallow copy, and with __clone() you can copy the nested objects too.

Si ta mendosh

Si ta fotokopjosh një dosje në vend që t'ia japësh origjinalin dikujt.

Lexoje në anglisht

Like photocopying a file instead of handing over the original.

Shembull kodiphp

$kopja = clone $origjinali;
$kopja->emri = "Tjetër";   // origjinali s'ndryshon

Terma të lidhur