Description
Description:
Using version creof/doctrine2-spatial v1.2.0 on PHP 8.4.5 results in a deprecation warning related to an implicitly nullable parameter in the AbstractPoint::validateArguments()
method.
Steps to reproduce:
- Install creof/doctrine2-spatial version 1.2.0 in a project using PHP 8.4.5.
- Trigger the creation of an AbstractPoint object, which will then call the validateArguments() function. This likely happens when using spatial functions/queries that involve point creation or manipulation.
- Observe the deprecation warning in the logs or output.
Expected behavior:
No deprecation warnings should be generated when creating or manipulating spatial point objects using creof/doctrine2-spatial v1.2.0 on PHP 8.4.5.
Actual behavior:
The following deprecation warning is generated:
Deprecated: CrEOF\Spatial\PHP\Types\AbstractPoint::validateArguments(): Implicitly marking parameter $argv as nullable is deprecated, the explicit nullable type must be used instead in /opt/vendor/creof/doctrine2-spatial/lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php on line 176
Root Cause:
The deprecation warning occurs because the validateArguments
method in the AbstractPoint
class uses an implicitly nullable parameter type declaration (array $argv = null)
for the $argv
parameter. PHP 8.1 and later require explicitly nullable type declarations (?array $argv)
.
Affected Code:
The relevant section of code is in CrEOF\Spatial\PHP\Types\AbstractPoint.php:
/
* @param array $argv
*
* @return array
* @throws InvalidValueException
*/
protected function validateArguments(array $argv = null)
{
$argc = count($argv);
if (1 == $argc && is_array($argv[0])) {
return $argv[0];
}
// ... (rest of the method)
}
Suggested Solution:
Update the method signature in AbstractPoint.php to use an explicitly nullable type declaration:
/
* @param array|null $argv
*
* @return array
* @throws InvalidValueException
*/
protected function validateArguments(?array $argv = null)
{
$argc = count($argv);
if (1 == $argc && is_array($argv[0])) {
return $argv[0];
}
// ... (rest of the method)
}
Environment:
• PHP version: 8.4.5
• Package version: creof/doctrine2-spatial v1.2.0
This change will ensure compatibility with PHP 8.1 and later versions and eliminate the deprecation warning. The @param docblock should also be updated to reflect the nullable type.