interconnectit / Search-Replace-DB

This script was made to aid the process of migrating PHP and MySQL based websites. Works with most common CMSes.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
GNU General Public License v3.0
3.99k stars 850 forks source link

Unexpected '/' #348

Closed Basemaly-pratt closed 3 years ago

Basemaly-pratt commented 3 years ago

Hello. Thank you for your excellent code. I ran into a problem, however, when trying to update a DB. I got the following error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting '{'

It seems to happen in various wp_#_options tables and I'm wondering how I can remedy this, or have it skip these tables. I tried using regex to exclude these tables, but it doesn't seem like regex works with the -w switch. Any help would be much appreciated. Thank you.

crossworth commented 3 years ago

I was facing the same problem. The problem is on the object_serializer function.

When we try create classes with namespace the error will be present. In my case was the class Elementor\Core\Logger\Items\JS.

Something like this should fix the problem.

function object_serializer( $class_name ) {

    $prefix = '';

    if (($pos = strrpos($class_name, "\\")) !== false) {
        $namespace = substr($class_name, 0, $pos);
        $class_name = substr($class_name, $pos + 1);
        $prefix = "namespace  {$namespace};";
    }

    eval( "{$prefix} class {$class_name} extends \ArrayObject {}" );
}
gianluigi-icit commented 3 years ago

Plug-in like Elementos are source of trouble for this script, has been discussed several times. Use 3.x or wp-cli :)

martijnimhoff commented 2 years ago

For anyone having this problem and stumbling on this thread. It was an error in the code of this project (https://github.com/interconnectit/Search-Replace-DB/pull/356).

It can be fixed by using the latest version of this tool.