Skip to main content

WPCodeBox Error Log

Error: "syntax error, unexpected identifier 'world'"

Error Message

This snippet was disabled because it triggered an error!
Error Message: syntax error, unexpected identifier "world"
On line: 1

Error Trace

#0 .../wpcodebox2/src/Service/WPCodeBox2.php(124): Wpcb2\Runner\QueryRunner->runQueries()
#1 .../wpcodebox2/wpcodebox2.php(57): Wpcb2\Service\WPCodeBox2->executeSnippets()
#2 /wp-settings.php(589): include_once('...')
#3 .../eval-command/src/EvalFile_Command.php(56): WP_CLI\Runner->load_wordpress()

Cause

This error occurs when the snippet's code field in the wp_wpcb_snippets table contains invalid PHP — specifically literal text like "hello world" instead of valid PHP code. This can happen during development/testing when test values are temporarily written to the database via WP-CLI commands such as:

wp eval '
$wpdb->update($wpdb->prefix . "wpcb_snippets",
["code" => "hello world"],
["id" => 2]
);
'

When WPCodeBox attempts to eval() the snippet code, it encounters hello (interpreted as an undefined constant) followed by world (an unexpected identifier), triggering a PHP parse error.

Resolution Steps

  1. Syntax check the current snippet code:

    wp db query --skip-column-names --raw 'SELECT code FROM wp_wpcb_snippets WHERE id={id}' > /tmp/snippet-check.php
    php -l /tmp/snippet-check.php
  2. Restore correct code by updating the snippet with valid PHP:

    wp eval '
    $code = file_get_contents("/path/to/correct-code.txt");
    global $wpdb;
    $wpdb->update(
    $wpdb->prefix . "wpcb_snippets",
    ["code" => $code],
    ["id" => {id}]
    );
    '
  3. Clear stored error fields in the database (WPCodeBox caches errors and disables the snippet):

    wp db query "UPDATE wp_wpcb_snippets
    SET enabled=1, error=0, errorMessage='', errorTrace='', errorLine=0
    WHERE id={id}"
  4. Verify the snippet is re-enabled and error-free:

    wp db query "SELECT id, enabled, error, errorMessage FROM wp_wpcb_snippets WHERE id={id}"

Prevention

  • Never write raw test strings directly to the code column via wpdb->update()
  • Always validate PHP syntax before writing snippet code
  • Use wp eval-file with a properly formatted PHP file instead of inline eval
  • Keep a backup of all working snippet code in version control