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 ;
31
30
use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
32
31
use PhpOffice \PhpSpreadsheet \Style \Style ;
33
32
34
- class Worksheet implements IComparable
33
+ class Worksheet
35
34
{
36
35
// Break types
37
36
public const BREAK_NONE = 0 ;
@@ -338,17 +337,10 @@ class Worksheet implements IComparable
338
337
*/
339
338
private $ tabColor ;
340
339
341
- /**
342
- * Dirty flag.
343
- *
344
- * @var bool
345
- */
346
- private $ dirty = true ;
347
-
348
340
/**
349
341
* Hash.
350
342
*
351
- * @var string
343
+ * @var int
352
344
*/
353
345
private $ hash ;
354
346
@@ -368,6 +360,7 @@ public function __construct(?Spreadsheet $parent = null, $title = 'Worksheet')
368
360
{
369
361
// Set parent and title
370
362
$ this ->parent = $ parent ;
363
+ $ this ->hash = spl_object_id ($ this );
371
364
$ this ->setTitle ($ title , false );
372
365
// setTitle can change $pTitle
373
366
$ this ->setCodeName ($ this ->getTitle ());
@@ -424,6 +417,12 @@ public function __destruct()
424
417
$ this ->rowDimensions = [];
425
418
}
426
419
420
+ public function __wakeup (): void
421
+ {
422
+ $ this ->hash = spl_object_id ($ this );
423
+ $ this ->parent = null ;
424
+ }
425
+
427
426
/**
428
427
* Return the cell collection.
429
428
*
@@ -914,7 +913,7 @@ public function setTitle($title, $updateFormulaCellReferences = true, $validate
914
913
// Syntax check
915
914
self ::checkSheetTitle ($ title );
916
915
917
- if ($ this ->parent ) {
916
+ if ($ this ->parent && $ this -> parent -> getIndex ( $ this , true ) >= 0 ) {
918
917
// Is there already such sheet name?
919
918
if ($ this ->parent ->sheetNameExists ($ title )) {
920
919
// Use name, but append with lowest possible integer
@@ -943,9 +942,8 @@ public function setTitle($title, $updateFormulaCellReferences = true, $validate
943
942
944
943
// Set title
945
944
$ this ->title = $ title ;
946
- $ this ->dirty = true ;
947
945
948
- if ($ this ->parent && $ this ->parent ->getCalculationEngine ()) {
946
+ if ($ this ->parent && $ this ->parent ->getIndex ( $ this , true ) >= 0 && $ this -> parent -> getCalculationEngine ()) {
949
947
// New title
950
948
$ newTitle = $ this ->getTitle ();
951
949
$ this ->parent ->getCalculationEngine ()
@@ -1088,7 +1086,6 @@ public function getProtection()
1088
1086
public function setProtection (Protection $ protection )
1089
1087
{
1090
1088
$ this ->protection = $ protection ;
1091
- $ this ->dirty = true ;
1092
1089
1093
1090
return $ this ;
1094
1091
}
@@ -3137,7 +3134,7 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
3137
3134
3138
3135
if ($ namedRange ->getLocalOnly ()) {
3139
3136
$ worksheet = $ namedRange ->getWorksheet ();
3140
- if ($ worksheet === null || $ this ->getHashCode () !== $ worksheet ->getHashCode ()) {
3137
+ if ($ worksheet === null || $ this ->getHashInt () !== $ worksheet ->getHashInt ()) {
3141
3138
if ($ returnNullIfInvalid ) {
3142
3139
return null ;
3143
3140
}
@@ -3278,17 +3275,20 @@ public function garbageCollect()
3278
3275
}
3279
3276
3280
3277
/**
3281
- * Get hash code .
3278
+ * @deprecated 3.5.0 use getHashInt instead .
3282
3279
*
3283
3280
* @return string Hash code
3284
3281
*/
3285
3282
public function getHashCode ()
3286
3283
{
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
+ }
3291
3286
3287
+ /**
3288
+ * @return int Hash code
3289
+ */
3290
+ public function getHashInt ()
3291
+ {
3292
3292
return $ this ->hash ;
3293
3293
}
3294
3294
@@ -3620,6 +3620,7 @@ public function __clone()
3620
3620
}
3621
3621
}
3622
3622
}
3623
+ $ this ->hash = spl_object_id ($ this );
3623
3624
}
3624
3625
3625
3626
/**
0 commit comments