Deprecation: #107413 - PathUtility getRelativePath(to) methods

See forge#107413

Description

The following methods in \TYPO3\CMS\Core\Utility\PathUtility have been marked as deprecated and will be removed in TYPO3 v15.0:

  • PathUtility::getRelativePath()
  • PathUtility::getRelativePathTo()

These methods are not needed anymore as TYPO3's path handling has been simplified due to the unification of the entry point URLs.

Since TYPO3 v13, both frontend and backend use the same main entry point ("htdocs/index.php"), making these relative path calculations obsolete.

Impact

Calling these methods will trigger a PHP deprecation warning. The methods will continue to work as before until they are removed in TYPO3 v15.0.

Affected installations

TYPO3 installations with custom extensions or code that directly call these deprecated methods:

  • PathUtility::getRelativePath()
  • PathUtility::getRelativePathTo()

The extension scanner will report any usage as strong match.

Migration

Instead of calculating relative paths manually, use absolute paths or the appropriate TYPO3 APIs for path handling:

  • Use GeneralUtility::getFileAbsFileName() for extension resources
  • Use the EXT: prefix for referencing extension resources
  • Use PathUtility::getPublicResourceWebPath() for public extension resources
  • Reference paths relative to the public web path of the TYPO3 installation
Before (deprecated)
$relativePath = PathUtility::getRelativePath($sourcePath, $targetPath);
$relativeToPath = PathUtility::getRelativePathTo($absolutePath);
Copied!
After (recommended)
// Use absolute paths or appropriate TYPO3 APIs
$absolutePath = GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Public/file.js');
$webPath = PathUtility::getPublicResourceWebPath('EXT:my_extension/Resources/Public/file.js');
Copied!