Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Named Arguments #324

Closed
kubawerlos opened this issue Jan 27, 2022 · 5 comments
Closed

Named Arguments #324

kubawerlos opened this issue Jan 27, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@kubawerlos
Copy link

Is breaking straightforward migration when named arguments are used a bug or feature?

E.g. this code - without Safe - will work fine:

    \json_decode($json, flags: \JSON_THROW_ON_ERROR);

migration to using Safe would require to changing flags to options though.

@dbrekelmans
Copy link
Collaborator

Which PHP version and which safe version are you using?

@kubawerlos
Copy link
Author

Both latest:

echo PHP_VERSION_ID, PHP_EOL,
    json_decode(file_get_contents(__DIR__. '/composer.lock'))->packages[0]->name, PHP_EOL,
    json_decode(file_get_contents(__DIR__. '/composer.lock'))->packages[0]->version, PHP_EOL,
    var_export((new \ReflectionFunction('Safe\json_decode'))->getParameters(), true), PHP_EOL,
    var_export((new \ReflectionFunction('\json_decode'))->getParameters(), true);
80102
thecodingmachine/safe
v2.1.1
array (
  0 => 
  ReflectionParameter::__set_state(array(
     'name' => 'json',
  )),
  1 => 
  ReflectionParameter::__set_state(array(
     'name' => 'assoc',
  )),
  2 => 
  ReflectionParameter::__set_state(array(
     'name' => 'depth',
  )),
  3 => 
  ReflectionParameter::__set_state(array(
     'name' => 'options',
  )),
)
array (
  0 => 
  ReflectionParameter::__set_state(array(
     'name' => 'json',
  )),
  1 => 
  ReflectionParameter::__set_state(array(
     'name' => 'associative',
  )),
  2 => 
  ReflectionParameter::__set_state(array(
     'name' => 'depth',
  )),
  3 => 
  ReflectionParameter::__set_state(array(
     'name' => 'flags',
  )),
)

@dbrekelmans
Copy link
Collaborator

Ah this is a bug then. Since json_decode is a special case function, it's not automatically updated when the phpdocs are changed.

If you are up for it, you can submit a PR changing the parameter names in https://github.com/thecodingmachine/safe/blob/master/lib/special_cases.php

@dbrekelmans dbrekelmans added the bug Something isn't working label Feb 2, 2022
@MarcinGladkowski
Copy link
Contributor

@dbrekelmans Hi! Consider my changes, please. #376

@dbrekelmans
Copy link
Collaborator

Fixed in #376

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants