2020use PhpOffice \PhpSpreadsheet \Comment ;
2121use PhpOffice \PhpSpreadsheet \DefinedName ;
2222use PhpOffice \PhpSpreadsheet \Exception ;
23- use PhpOffice \PhpSpreadsheet \IComparable ;
2423use PhpOffice \PhpSpreadsheet \ReferenceHelper ;
2524use PhpOffice \PhpSpreadsheet \RichText \RichText ;
2625use PhpOffice \PhpSpreadsheet \Shared ;
3130use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
3231use PhpOffice \PhpSpreadsheet \Style \Style ;
3332
34- class Worksheet implements IComparable
33+ class Worksheet
3534{
3635 // Break types
3736 public const BREAK_NONE = 0 ;
@@ -338,17 +337,10 @@ class Worksheet implements IComparable
338337 */
339338 private $ tabColor ;
340339
341- /**
342- * Dirty flag.
343- *
344- * @var bool
345- */
346- private $ dirty = true ;
347-
348340 /**
349341 * Hash.
350342 *
351- * @var string
343+ * @var int
352344 */
353345 private $ hash ;
354346
@@ -368,6 +360,7 @@ public function __construct(?Spreadsheet $parent = null, $title = 'Worksheet')
368360 {
369361 // Set parent and title
370362 $ this ->parent = $ parent ;
363+ $ this ->hash = spl_object_id ($ this );
371364 $ this ->setTitle ($ title , false );
372365 // setTitle can change $pTitle
373366 $ this ->setCodeName ($ this ->getTitle ());
@@ -424,6 +417,12 @@ public function __destruct()
424417 $ this ->rowDimensions = [];
425418 }
426419
420+ public function __wakeup (): void
421+ {
422+ $ this ->hash = spl_object_id ($ this );
423+ $ this ->parent = null ;
424+ }
425+
427426 /**
428427 * Return the cell collection.
429428 *
@@ -914,7 +913,7 @@ public function setTitle($title, $updateFormulaCellReferences = true, $validate
914913 // Syntax check
915914 self ::checkSheetTitle ($ title );
916915
917- if ($ this ->parent ) {
916+ if ($ this ->parent && $ this -> parent -> getIndex ( $ this , true ) >= 0 ) {
918917 // Is there already such sheet name?
919918 if ($ this ->parent ->sheetNameExists ($ title )) {
920919 // Use name, but append with lowest possible integer
@@ -943,9 +942,8 @@ public function setTitle($title, $updateFormulaCellReferences = true, $validate
943942
944943 // Set title
945944 $ this ->title = $ title ;
946- $ this ->dirty = true ;
947945
948- if ($ this ->parent && $ this ->parent ->getCalculationEngine ()) {
946+ if ($ this ->parent && $ this ->parent ->getIndex ( $ this , true ) >= 0 && $ this -> parent -> getCalculationEngine ()) {
949947 // New title
950948 $ newTitle = $ this ->getTitle ();
951949 $ this ->parent ->getCalculationEngine ()
@@ -1088,7 +1086,6 @@ public function getProtection()
10881086 public function setProtection (Protection $ protection )
10891087 {
10901088 $ this ->protection = $ protection ;
1091- $ this ->dirty = true ;
10921089
10931090 return $ this ;
10941091 }
@@ -3137,7 +3134,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
31373134
31383135 if ($ namedRange ->getLocalOnly ()) {
31393136 $ worksheet = $ namedRange ->getWorksheet ();
3140- if ($ worksheet === null || $ this ->getHashCode () !== $ worksheet ->getHashCode ()) {
3137+ if ($ worksheet === null || $ this ->getHashInt () !== $ worksheet ->getHashInt ()) {
31413138 if ($ returnNullIfInvalid ) {
31423139 return null ;
31433140 }
@@ -3278,17 +3275,20 @@ public function garbageCollect()
32783275 }
32793276
32803277 /**
3281- * Get hash code .
3278+ * @deprecated 3.5.0 use getHashInt instead .
32823279 *
32833280 * @return string Hash code
32843281 */
32853282 public function getHashCode ()
32863283 {
3287- if ($ this ->dirty ) {
3288- $ this ->hash = md5 ($ this ->title . $ this ->autoFilter . ($ this ->protection ->isProtectionEnabled () ? 't ' : 'f ' ) . __CLASS__ );
3289- $ this ->dirty = false ;
3290- }
3284+ return (string ) $ this ->hash ;
3285+ }
32913286
3287+ /**
3288+ * @return int Hash code
3289+ */
3290+ public function getHashInt ()
3291+ {
32923292 return $ this ->hash ;
32933293 }
32943294
@@ -3620,6 +3620,7 @@ public function __clone()
36203620 }
36213621 }
36223622 }
3623+ $ this ->hash = spl_object_id ($ this );
36233624 }
36243625
36253626 /**
0 commit comments