-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony\Component\VarDumper\Caster\SymfonyCaster doesn't check array key exist #33751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for the report. Can you please share a reproducer? I just had a quick look at the source code of tinker and I don't get how it's related to request/http-client casters. |
@zcodes Do you have any news for us? |
this is a piece of code demo the problem: <?php
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\VarDumper\Caster\Caster;
require_once __DIR__ . '/vendor/autoload.php';
$cloner = new VarCloner();
$cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
if ($filter || $isNested) {
if ($obj instanceof \Exception) {
$a = Caster::filter($a, Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_EMPTY);
} else {
$a = Caster::filter($a, Caster::EXCLUDE_PROTECTED | Caster::EXCLUDE_PRIVATE);
}
}
return $a;
}]);
$client = HttpClient::create();
$data = $cloner->cloneVar($client, Caster::EXCLUDE_VERBOSE); |
OK, got it thanks for the code. Many casters are affected then, isn't it? |
@nicolas-grekas I make a pr #33919 , hope this is helpful. |
…codes) This PR was squashed before being merged into the 4.3 branch (closes #33919). Discussion ---------- [VarDumper] fix array key error for class SymfonyCaster | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #33751 | License | MIT | Doc PR | - Commits ------- 1f20f35 [VarDumper] fix array key error for class SymfonyCaster
in the class method
castRequest
andcastHttpClient
, argument array$a
is used without checking the array key exists, by default, there's no problem, but if there's filter before called SymfonyCaster (like in laravel's tinker), the array$a
is empty, then it will raise an index error exception.The text was updated successfully, but these errors were encountered: