Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in save or retrieve #182

Open
apeivandi opened this issue Dec 11, 2021 · 1 comment · Fixed by Livijn/laravel-mysql-spatial#1 · May be fixed by #198
Open

Error in save or retrieve #182

apeivandi opened this issue Dec 11, 2021 · 1 comment · Fixed by Livijn/laravel-mysql-spatial#1 · May be fixed by #198

Comments

@apeivandi
Copy link

Hi
My code was working fine and all of the sudden I'm getting a real strange error. (really all of the sudden! I didn't change a line of code! Only my mac got updated to latest version which I honestly don't see how that could be an issue!)

When I try to save or retrieve any entity that has a point data type in it I get this exception:
PHP Fatal error: During inheritance of JsonSerializable: Uncaught ErrorException: Return type of Grimzy\LaravelMysqlSpatial\Types\Point::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/amirpeivandi/Projects/nwrewards/vendor/grimzy/laravel-mysql-spatial/src/Types/Point.php:93

Any idea what this could be?

Amir

@bossrabbit
Copy link

I'm experiencing the same problem with PHP 8.1.2 and Laravel 8.65 and version 5.0.0 of this package.

If you are running PHP 8.1 and higher you can suppress this error by adding the attribute #[\ReturnTypeWillChange] before the jsonSerialize() method in .../vendor/grimzy/laravel-mysql-spatial/src/Types/Point.php. More about this new attribute here.

    /**
     * Convert to GeoJson Point that is jsonable to GeoJSON.
     *
     * @return \GeoJson\Geometry\Point
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        return new GeoJsonPoint([$this->getLng(), $this->getLat()]);
    }

Livijn added a commit to Livijn/laravel-mysql-spatial that referenced this issue Nov 8, 2022
Right now this lib throws:

> Return type of Grimzy\LaravelMysqlSpatial\Types\Point::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in xxx/vendor/grimzy/laravel-mysql-spatial/src/Types/Point.php on line 95

Fixes grimzy#182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants