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
}
@@ -2994,7 +2993,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
2994
2993
2995
2994
if ($ namedRange ->getLocalOnly ()) {
2996
2995
$ worksheet = $ namedRange ->getWorksheet ();
2997
- if ($ worksheet === null || $ this ->getHashCode () !== $ worksheet ->getHashCode ()) {
2996
+ if ($ worksheet === null || $ this ->hash !== $ worksheet ->getHashInt ()) {
2998
2997
if ($ returnNullIfInvalid ) {
2999
2998
return null ;
3000
2999
}
@@ -3131,17 +3130,15 @@ public function garbageCollect(): static
3131
3130
}
3132
3131
3133
3132
/**
3134
- * Get hash code.
3135
- *
3136
- * @return string Hash code
3133
+ * @deprecated 3.5.0 use getHashInt instead.
3137
3134
*/
3138
3135
public function getHashCode (): string
3139
3136
{
3140
- if ($ this ->dirty ) {
3141
- $ this ->hash = md5 ($ this ->title . $ this ->autoFilter . ($ this ->protection ->isProtectionEnabled () ? 't ' : 'f ' ) . __CLASS__ );
3142
- $ this ->dirty = false ;
3143
- }
3137
+ return (string ) $ this ->hash ;
3138
+ }
3144
3139
3140
+ public function getHashInt (): int
3141
+ {
3145
3142
return $ this ->hash ;
3146
3143
}
3147
3144
@@ -3470,6 +3467,7 @@ public function __clone()
3470
3467
}
3471
3468
}
3472
3469
}
3470
+ $ this ->hash = spl_object_id ($ this );
3473
3471
}
3474
3472
3475
3473
/**
0 commit comments