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 ;
3231use PhpOffice \PhpSpreadsheet \Style \Protection as StyleProtection ;
3332use PhpOffice \PhpSpreadsheet \Style \Style ;
3433
35- class Worksheet implements IComparable
34+ class Worksheet
3635{
3736 // Break types
3837 public const BREAK_NONE = 0 ;
@@ -305,15 +304,10 @@ class Worksheet implements IComparable
305304 */
306305 private ?Color $ tabColor = null ;
307306
308- /**
309- * Dirty flag.
310- */
311- private bool $ dirty = true ;
312-
313307 /**
314308 * Hash.
315309 */
316- private string $ hash ;
310+ private int $ hash ;
317311
318312 /**
319313 * CodeName.
@@ -327,6 +321,7 @@ public function __construct(?Spreadsheet $parent = null, string $title = 'Worksh
327321 {
328322 // Set parent and title
329323 $ this ->parent = $ parent ;
324+ $ this ->hash = spl_object_id ($ this );
330325 $ this ->setTitle ($ title , false );
331326 // setTitle can change $pTitle
332327 $ this ->setCodeName ($ this ->getTitle ());
@@ -383,6 +378,12 @@ public function __destruct()
383378 unset($ this ->rowDimensions , $ this ->columnDimensions , $ this ->tableCollection , $ this ->drawingCollection , $ this ->chartCollection , $ this ->autoFilter );
384379 }
385380
381+ public function __wakeup (): void
382+ {
383+ $ this ->hash = spl_object_id ($ this );
384+ $ this ->parent = null ;
385+ }
386+
386387 /**
387388 * Return the cell collection.
388389 */
@@ -862,7 +863,7 @@ public function setTitle(string $title, bool $updateFormulaCellReferences = true
862863 // Syntax check
863864 self ::checkSheetTitle ($ title );
864865
865- if ($ this ->parent ) {
866+ if ($ this ->parent && $ this -> parent -> getIndex ( $ this , true ) >= 0 ) {
866867 // Is there already such sheet name?
867868 if ($ this ->parent ->sheetNameExists ($ title )) {
868869 // Use name, but append with lowest possible integer
@@ -891,9 +892,8 @@ public function setTitle(string $title, bool $updateFormulaCellReferences = true
891892
892893 // Set title
893894 $ this ->title = $ title ;
894- $ this ->dirty = true ;
895895
896- if ($ this ->parent && $ this ->parent ->getCalculationEngine ()) {
896+ if ($ this ->parent && $ this ->parent ->getIndex ( $ this , true ) >= 0 && $ this -> parent -> getCalculationEngine ()) {
897897 // New title
898898 $ newTitle = $ this ->getTitle ();
899899 $ this ->parent ->getCalculationEngine ()
@@ -1026,7 +1026,6 @@ public function getProtection(): Protection
10261026 public function setProtection (Protection $ protection ): static
10271027 {
10281028 $ this ->protection = $ protection ;
1029- $ this ->dirty = true ;
10301029
10311030 return $ this ;
10321031 }
@@ -2984,7 +2983,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
29842983
29852984 if ($ namedRange ->getLocalOnly ()) {
29862985 $ worksheet = $ namedRange ->getWorksheet ();
2987- if ($ worksheet === null || $ this ->getHashCode () !== $ worksheet ->getHashCode ()) {
2986+ if ($ worksheet === null || $ this ->hash !== $ worksheet ->getHashInt ()) {
29882987 if ($ returnNullIfInvalid ) {
29892988 return null ;
29902989 }
@@ -3121,17 +3120,15 @@ public function garbageCollect(): static
31213120 }
31223121
31233122 /**
3124- * Get hash code.
3125- *
3126- * @return string Hash code
3123+ * @deprecated 3.5.0 use getHashInt instead.
31273124 */
31283125 public function getHashCode (): string
31293126 {
3130- if ($ this ->dirty ) {
3131- $ this ->hash = md5 ($ this ->title . $ this ->autoFilter . ($ this ->protection ->isProtectionEnabled () ? 't ' : 'f ' ) . __CLASS__ );
3132- $ this ->dirty = false ;
3133- }
3127+ return (string ) $ this ->hash ;
3128+ }
31343129
3130+ public function getHashInt (): int
3131+ {
31353132 return $ this ->hash ;
31363133 }
31373134
@@ -3460,6 +3457,7 @@ public function __clone()
34603457 }
34613458 }
34623459 }
3460+ $ this ->hash = spl_object_id ($ this );
34633461 }
34643462
34653463 /**
0 commit comments