20
20
use PhpOffice \PhpSpreadsheet \Comment ;
21
21
use PhpOffice \PhpSpreadsheet \DefinedName ;
22
22
use PhpOffice \PhpSpreadsheet \Exception ;
23
- use PhpOffice \PhpSpreadsheet \IComparable ;
24
23
use PhpOffice \PhpSpreadsheet \ReferenceHelper ;
25
24
use PhpOffice \PhpSpreadsheet \RichText \RichText ;
26
25
use PhpOffice \PhpSpreadsheet \Shared ;
32
31
use PhpOffice \PhpSpreadsheet \Style \Protection as StyleProtection ;
33
32
use PhpOffice \PhpSpreadsheet \Style \Style ;
34
33
35
- class Worksheet implements IComparable
34
+ class Worksheet
36
35
{
37
36
// Break types
38
37
public const BREAK_NONE = 0 ;
@@ -305,15 +304,10 @@ class Worksheet implements IComparable
305
304
*/
306
305
private ?Color $ tabColor = null ;
307
306
308
- /**
309
- * Dirty flag.
310
- */
311
- private bool $ dirty = true ;
312
-
313
307
/**
314
308
* Hash.
315
309
*/
316
- private string $ hash ;
310
+ private int $ hash ;
317
311
318
312
/**
319
313
* CodeName.
@@ -327,6 +321,7 @@ public function __construct(?Spreadsheet $parent = null, string $title = 'Worksh
327
321
{
328
322
// Set parent and title
329
323
$ this ->parent = $ parent ;
324
+ $ this ->hash = spl_object_id ($ this );
330
325
$ this ->setTitle ($ title , false );
331
326
// setTitle can change $pTitle
332
327
$ this ->setCodeName ($ this ->getTitle ());
@@ -383,6 +378,12 @@ public function __destruct()
383
378
unset($ this ->rowDimensions , $ this ->columnDimensions , $ this ->tableCollection , $ this ->drawingCollection , $ this ->chartCollection , $ this ->autoFilter );
384
379
}
385
380
381
+ public function __wakeup (): void
382
+ {
383
+ $ this ->hash = spl_object_id ($ this );
384
+ $ this ->parent = null ;
385
+ }
386
+
386
387
/**
387
388
* Return the cell collection.
388
389
*/
@@ -862,7 +863,7 @@ public function setTitle(string $title, bool $updateFormulaCellReferences = true
862
863
// Syntax check
863
864
self ::checkSheetTitle ($ title );
864
865
865
- if ($ this ->parent ) {
866
+ if ($ this ->parent && $ this -> parent -> getIndex ( $ this , true ) >= 0 ) {
866
867
// Is there already such sheet name?
867
868
if ($ this ->parent ->sheetNameExists ($ title )) {
868
869
// Use name, but append with lowest possible integer
@@ -891,9 +892,8 @@ public function setTitle(string $title, bool $updateFormulaCellReferences = true
891
892
892
893
// Set title
893
894
$ this ->title = $ title ;
894
- $ this ->dirty = true ;
895
895
896
- if ($ this ->parent && $ this ->parent ->getCalculationEngine ()) {
896
+ if ($ this ->parent && $ this ->parent ->getIndex ( $ this , true ) >= 0 && $ this -> parent -> getCalculationEngine ()) {
897
897
// New title
898
898
$ newTitle = $ this ->getTitle ();
899
899
$ this ->parent ->getCalculationEngine ()
@@ -1026,7 +1026,6 @@ public function getProtection(): Protection
1026
1026
public function setProtection (Protection $ protection ): static
1027
1027
{
1028
1028
$ this ->protection = $ protection ;
1029
- $ this ->dirty = true ;
1030
1029
1031
1030
return $ this ;
1032
1031
}
@@ -2984,7 +2983,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
2984
2983
2985
2984
if ($ namedRange ->getLocalOnly ()) {
2986
2985
$ worksheet = $ namedRange ->getWorksheet ();
2987
- if ($ worksheet === null || $ this ->getHashCode () !== $ worksheet ->getHashCode ()) {
2986
+ if ($ worksheet === null || $ this ->hash !== $ worksheet ->getHashInt ()) {
2988
2987
if ($ returnNullIfInvalid ) {
2989
2988
return null ;
2990
2989
}
@@ -3121,17 +3120,15 @@ public function garbageCollect(): static
3121
3120
}
3122
3121
3123
3122
/**
3124
- * Get hash code.
3125
- *
3126
- * @return string Hash code
3123
+ * @deprecated 3.5.0 use getHashInt instead.
3127
3124
*/
3128
3125
public function getHashCode (): string
3129
3126
{
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
+ }
3134
3129
3130
+ public function getHashInt (): int
3131
+ {
3135
3132
return $ this ->hash ;
3136
3133
}
3137
3134
@@ -3460,6 +3457,7 @@ public function __clone()
3460
3457
}
3461
3458
}
3462
3459
}
3460
+ $ this ->hash = spl_object_id ($ this );
3463
3461
}
3464
3462
3465
3463
/**
0 commit comments