Seldaek/monolog · error · UnexpectedValueException

Expected the first arg to be a string, got: ${method}

Error message

Expected the first arg to be a string, got: ${method}

What it means

Error "Expected the first arg to be a string, got: ${method}" thrown in Seldaek/monolog.

Source

Thrown at src/Monolog/Handler/BrowserConsoleHandler.php:287

            $script[] = self::call('log', self::quote('%s: %o'), self::quote((string) $key), $value);
        }

        return $script;
    }

    private static function quote(string $arg): string
    {
        return '"' . addcslashes($arg, "\"\n\\") . '"';
    }

    /**
     * @param mixed $args
     */
    private static function call(...$args): string
    {
        $method = array_shift($args);
        if (!\is_string($method)) {
            throw new \UnexpectedValueException('Expected the first arg to be a string, got: '.var_export($method, true));
        }

        return self::call_array($method, $args);
    }

    /**
     * @param mixed[] $args
     */
    private static function call_array(string $method, array $args): string
    {
        return 'c.' . $method . '(' . implode(', ', $args) . ');';
    }
}

View on GitHub (pinned to 57eb102834)

When it happens

Trigger: Thrown at src/Monolog/Handler/BrowserConsoleHandler.php:287 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Seldaek/monolog@57eb102834 (2026-08-17). Data as JSON: /api/errors/92aa54fbc3a910ad. Report an issue: GitHub.