Skip to content

Fix callMethodOnDumper treating false config values as no-argument calls#1961

Merged
freekmurze merged 2 commits intospatie:mainfrom
isaackaara:fix/call-method-on-dumper-falsy-value
Mar 8, 2026
Merged

Fix callMethodOnDumper treating false config values as no-argument calls#1961
freekmurze merged 2 commits intospatie:mainfrom
isaackaara:fix/call-method-on-dumper-falsy-value

Conversation

@isaackaara
Copy link
Contributor

What this fixes

When a dump config option is set to false, callMethodOnDumper was calling the method with no arguments because of the falsy check:

if (! $methodValue) {
    $dbDumper->$methodName();  // setSkipSsl() defaults to true
    return $dbDumper;
}

The issue is setSkipSsl() (and similar methods on DbDumper) have bool $param = true as the default parameter. So calling them with no arguments sets the value to true even when the config explicitly says false.

Reproduction:

// config/database.php
'dump' => [
    'skip_ssl' => false,
],

The dumper ends up with skipSsl = true because:

  1. Line 51 correctly sets it to false
  2. processExtraDumpParameters then processes the dump config again, hitting skip_ssl => false
  3. callMethodOnDumper sees !false === true and calls setSkipSsl() with no args → defaults to true

Fix

Change the check from ! $methodValue to $methodValue === null. Flag-style options (like use_single_transaction) produce a null $methodValue from processExtraDumpParameters, so those still call the no-argument form. Falsy values like false and 0 are now passed through correctly.

// Before
if (! $methodValue) {

// After
if ($methodValue === null) {

Test added

Added a test that confirms skip_ssl => false in the dump config results in skipSsl being false on the dumper.

Relates to: #1946

isaackaara and others added 2 commits March 6, 2026 14:16
When a dump config option like skip_ssl is set to false, callMethodOnDumper
was calling the method with no arguments because of the falsy check:

    if (! $methodValue) { $dbDumper->$methodName(); }

setSkipSsl() has a default parameter of true, so calling it with no
arguments sets skipSsl to true even when the config says false.

Change the check to $methodValue === null so only genuinely absent
values (flag-style options like use_single_transaction) invoke
the no-argument form. Falsy values like false and 0 are now passed
through correctly.

Fixes: spatie#1946
The 'custom dumpers' test registers a MongoDb factory for 'mysql'
via the static $custom property, which persisted into subsequent
tests causing the skip_ssl test to get a MongoDb instance instead
of MySql.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@freekmurze freekmurze merged commit 14ff782 into spatie:main Mar 8, 2026
5 checks passed
@freekmurze
Copy link
Member

Thanks for the fix and the clear write-up, @isaackaara!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants