Skip to content
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

bad work in closure with null argument #35

Open
m-derakhshi opened this issue Jan 30, 2025 · 3 comments
Open

bad work in closure with null argument #35

m-derakhshi opened this issue Jan 30, 2025 · 3 comments

Comments

@m-derakhshi
Copy link

m-derakhshi commented Jan 30, 2025

when i use code

print_r( '<?php return '.\Brick\VarExporter\VarExporter::export($array,0,0).';'.PHP_EOL);

and $array is :

$array = [ 'id' => [
    'type' => 'searchableEnums',
    'label' => '__::articleCategory/articleCategory.module.name.plural',
    'options' => fn (string|array|null $values) => App(ArticleCategoryService::class)->searchableArticleCategoryEnum($values),
]];

response is : [ function (string|array|\Projects\Controllers\null $values) ]

<?php return [
    'id' => [
        'type' => 'searchableEnums',
        'label' => '__::articleCategory/articleCategory.module.name.plural',
        'options' => function (string|array|\Projects\Controllers\null $values){
            return App(\ArticleCategory\ArticleCategoryService::class)->searchableArticleCategoryEnum($values);
        }
    ]
];
@BenMorel
Copy link
Member

BenMorel commented Feb 4, 2025

Indeed, this is a bug, thanks for reporting it!

Full reproduce:

namespace Project\Controllers;
use Brick\VarExporter\VarExporter;

require 'vendor/autoload.php';

$function = function (string|array|null $values): string|null {
    return null;
};

$fn = fn (string|array|null $values): string|null => null;

echo VarExporter::export($function), "\n";
echo VarExporter::export($fn), "\n";

Expected output:

function (string|array|null $values): string|null {
    return null;
}
function (string|array|null $values): string|null {
    return null;
}

Actual output:

function (string|array|\Project\Controllers\null $values): string|\Project\Controllers\null {
    return null;
}
function (string|array|\Project\Controllers\null $values): string|\Project\Controllers\null {
    return null;
}

Maybe @jasny could help?

@jasny
Copy link
Contributor

jasny commented Feb 4, 2025

This seems to be a bug in https://github.com/nikic/PHP-Parser. We need to open an issue there.

@BenMorel
Copy link
Member

BenMorel commented Feb 4, 2025

Thanks for taking a look, @jasny! Do you want to take care of it?

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

No branches or pull requests

3 participants