Summer Sale! All accounts are 50% off this week.

monstajamss's avatar

implode(): Passing glue string after array is deprecated

I am trying to make a post and i got this error ErrorException (E_DEPRECATED) implode(): Passing glue string after array is deprecated. Swap the parameters

C:\MAMP\htdocs\naijaswiftforum\vendor\cviebrock\eloquent-sluggable\src\Services\SlugService.php
     * @param mixed $from
     *
     * @return string
     */
    protected function getSlugSource($from): string
    {
        if (is_null($from)) {
            return $this->model->__toString();
        }
 
        $sourceStrings = array_map(function($key) {
            $value = data_get($this->model, $key);
            if (is_bool($value)) {
                $value = (int) $value;
            }
 
            return $value;
        }, (array) $from);
 
        return implode($sourceStrings, ' ');
    }
 
    /**
     * Generate a slug from the given source string.
     *
     * @param string $source
     * @param array $config
     * @param string $attribute
     *
     * @return string
     * @throws \UnexpectedValueException
     */
    protected function generateSlug(string $source, array $config, string $attribute): string
    {
        $separator = $config['separator'];

Can someone help?

0 likes
10 replies
Snapey's avatar

What it says

return implode(' ', $sourceStrings);
MichalOravec's avatar

@monstajamss I think this "ErrorException (E_DEPRECATED) implode(): Passing glue string after array is deprecated. Swap the parameters" is pretty clear.

Documentation: https://www.php.net/manual/en/function.implode.php

Note: implode() can, for historical reasons, accept its parameters in either order. For consistency with explode(), however, it is deprecated not to use the documented order of arguments.

PresKhaled's avatar

From PHP Manual

implode ( string $glue , array $pieces ) : string

Version: 7.4.0 | Passing the glue after the pieces (i.e. not using the documented order of parameters) has been deprecated.

Snapey's avatar

I showed you the line that needs to be changed. If you need any more clues its the line with IMPLODE

jlrdw's avatar
      return implode(' ', $sourceStrings);

Like @Jeffreyway once reminded me, we were all new to programming at one time.

monstajamss's avatar

Thanks everyone for answering, i really appreciate it. I was able to solve the problem by upgrading my Laravel project from Version 5 to Version 7. After doing that the website worked and i did not get that problem anymore.

Once again thanks @snapey @jeffreyway @michaloravec @preskhaled @jlrdw

1 like
Snapey's avatar

I apologise. I did not notice that your issue was inside the package cviebrock\eloquent-sluggable

Presumably this package was able to be upgraded with the latest Laravel 7

jlrdw's avatar

Glad you got it working. What the forum is all about trying to help folks.

aurawindsurfing's avatar

This error also exists if you are using php 7.4 while your project should be running on php 7.3 which of course is equivalent to update of laravel to version 7 ;-)

Please or to participate in this conversation.