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

web_services: missing params result in bad function call #9411

Closed
mrclay opened this Issue Feb 23, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@mrclay
Member

mrclay commented Feb 23, 2016

(Very old issue but I couldn't find a ticket for it.)

elgg_ws_expose_function('test', 'api_test', [
    'one' => ['required' => false, 'type' => 'int'],
     'two' => ['required' => true, 'type' => 'int']
]);

function api_test($one, $two) {}

http://example.org/services/api/rest/json/?method=test&two=2 results in 2 being passed in as $one, and a PHP warning about missing argument $two (null within the function).

Workaround: give the "one" parameter a non-null default.

Given there's a tiny chance devs are relying on this undocumented behavior, can we fix this in 2.x?

  • Steve 👍
  • Ismayil 👍
@hypeJunction

This comment has been minimized.

Show comment
Hide comment
@hypeJunction

hypeJunction Feb 23, 2016

Contributor

I believe I ran into it before and used the default parameter

Contributor

hypeJunction commented Feb 23, 2016

I believe I ran into it before and used the default parameter

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Feb 23, 2016

Member

I put you down for a +1 vote for fixing.

Member

mrclay commented Feb 23, 2016

I put you down for a +1 vote for fixing.

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 24, 2016

feature(web_services): allows API function to be given an associative…
… array

An additional flag allows the API function to receive a single array of
named parameters.

Any callable can be used as the API function.

Static method API functions no longer autoload the class at registration
time.

Missing parameters with no default value now are passed as `null` to the
API function. No longer are the remaining arguments shifted left.

Fixes #9411

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Feb 24, 2016

feature(web_services): allows API function to be given an associative…
… array

An additional flag allows the API function to receive a single array of
named parameters.

Any callable can be used as the API function.

Missing parameters with no default value now are passed as `null` to the
API function. No longer are the remaining arguments shifted left.

Fixes #9411
@mrclay

This comment has been minimized.

Show comment
Hide comment
Member

mrclay commented Feb 24, 2016

PR #9418

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Apr 6, 2016

feature(web_services): allows API function to be given an associative…
… array

An additional flag allows the API function to receive a single array of
named parameters.

Any callable can be used as the API function.

Missing parameters with no default value now are passed as `null` to the
API function. No longer are the remaining arguments shifted left.

Fixes #9411
Conflicts:
	mod/web_services/tests/ElggCoreWebServicesApiTest.php

@jdalsem jdalsem closed this in #9418 Apr 12, 2016

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