Skip to content

Commit

Permalink
[BUGFIX] Stabilize AbstractDomainObject _isDirty check
Browse files Browse the repository at this point in the history
Accessing static properties as non-static has always
triggered a notice in PHP. However, since PHP 8.0
accessing undefined properties (which always comes with
the former notice) is now a warning. This will be
caught by the error handler in debug mode.

To fix this, the more robust _getProperty method is
backported from #100120 and used in the _isDirty method.

Resolves: #101488
Related: #100120
Releases: 11.5
Change-Id: I5f9ccb411f02f0dcc164d0d14917ecd631dc1178
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80280
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
nhovratov authored and sbuerk committed Sep 7, 2023
1 parent d50216f commit 8a16e93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -128,7 +128,9 @@ public function _setProperty(string $propertyName, $propertyValue)
*/
public function _getProperty(string $propertyName)
{
return $this->{$propertyName};
return $this->_hasProperty($propertyName) && isset($this->{$propertyName})
? $this->{$propertyName}
: null;
}

/**
Expand Down Expand Up @@ -262,7 +264,7 @@ public function _isDirty($propertyName = null)
}
}
} else {
if ($this->isPropertyDirty($this->_getCleanProperty($propertyName), $this->{$propertyName}) === true) {
if ($this->isPropertyDirty($this->_getCleanProperty($propertyName), $this->_getProperty($propertyName)) === true) {
return true;
}
}
Expand Down
Expand Up @@ -133,4 +133,13 @@ public function lazyLoadingProxyByWrongLazyLoadingProxyIsDirtyAndUpdated(): void
$updatedBlogOne = $this->blogRepository->findByUid(3);
self::assertSame($updatedBlogOne->getAdministrator()->getUid(), $blogTwo->getAdministrator()->getUid());
}

/**
* @test
*/
public function undefinedPropertyIsAlwaysClean(): void
{
$blogOne = $this->blogRepository->findByUid(1);
self::assertFalse($blogOne->_isDirty('undefinedProperty'));
}
}

0 comments on commit 8a16e93

Please sign in to comment.