0

I'm sending the following json: {"name":"New event"}

to a PATCH handler: function patch($id, $request_data = NULL)

but am getting the following warning: Warning: strlen() expects parameter 1 to be string, array given in /public_html/vendor/Luracast/Restler/Data/Validator.php on line 115

The source at that line is:

switch ($info->type) {
    ...
    case 'string' :
       $r = strlen($input);

So I added some code to the first line of Validator.validate() see what it thinks the variables are:

print("$input: $info->type\n");

and I get this:

1: int
Array: string

So it thinks the array is a string. It is still able to continue and process the request, but it returns this warning as the response instead of something valid I can process.

Any ideas what I'm doing wrong?

Lys777
  • 426
  • 1
  • 3
  • 11
  • For now I have added this to Validator.php: `if (is_array($input)) $info->type = "array";` to the top of the validate function and it is fixing the problem, but I'm not sure if that is the best approach. – Lys777 Jul 26 '13 at 20:46
  • changing the $info->type in Validator class is not the right way. Are you using any php doc comments for the parse method? if so, please add it to the code above – Arul Kumaran Aug 04 '13 at 04:55

2 Answers2

1

Latest version (Restler 3 RC4) in v3 branch fixes this issue

Arul Kumaran
  • 983
  • 7
  • 23
1

I had this problem too, but that's because I gave param wrong type.

For example

@param string $request_data

change type

 string to mixed 

the problem will be solved.

zhangjun
  • 51
  • 8