Page 1 of 2

[Fixed] TM-WS does not work with PHP 5.2.x

Posted: 08 May 2011, 20:14
by m4rcel
So after getting access to the TM WebServices (thanks for this :D), I of course tried to write a simple script, calling the NickName to a login. And I had to notice, that the SDK is currently not working under PHP 5.2.x (exactly 5.2.14), whereas the Requirements say "PHP 5.2 or newer".


In detail, I found the following errors/problems so far:
  • Fatal error: func_get_args(): Can't be used as a function parameter in /.../trackmania-ws.php on line 72 (and other lines)
    This error is caused due to using the func_get_args() as a parameter for another method call, and seems not to be possible as of PHP 5.2.
    Workaround:
    Replace all similar lines to

    Code: Select all

    return $this->executeGET('/tmf/players/%s/', func_get_args());
    with e.g.

    Code: Select all

    $params = get_func_args();
    return $this->executeGET('/tmf/players/%s/', $params);
  • Fatal error: Call to undefined function json_last_error() in /.../trackmania-ws.php on line 474
    json_last_error() has been introduced with PHP 5.3, and seems not to have any replacement in PHP 5.2 though. I think the only possibility on this point is to remove the error handling in case of PHP 5.2, and to only differentiate between "well formed JSON" and "malformed JSON" without any deeper debugging information.

It would be nice, if you can handle these errors to make the SDK compatible to PHP 5.2, rather than changing the requirements to PHP 5.3 ;)

FT»Marcel

Re: TM-WS does not work with PHP 5.2.x

Posted: 08 May 2011, 20:24
by TheM
m4rcel wrote:It would be nice, if you can handle these errors to make the SDK compatible to PHP 5.2, rather than changing the requirements to PHP 5.3 ;)
Indeed, since most of the production servers (hosters) are still using 5.2 :|

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 10:16
by gouxim
Thanks for the report. We indeed wanted to make à 5.2 SDK although all our codebase is 5.3. I'll update the SDK to make it compatible.

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 11:00
by gouxim
I fixed that in 0.3, should be working now. I left the json_last_error but with a function_exists check before.

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 11:13
by w1lla
It works. Thanks for the fix.

Preview can be found under:

http://tmrankings.com/intr/examples/test1.php

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 11:35
by m4rcel
Thanks for the update :)

I found another use of json_last_error() in line 493 ;)

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 11:45
by gouxim
m4rcel wrote:I found another use of json_last_error() in line 493 ;)
gou1 wrote:I left the json_last_error but with a function_exists check before.
:geek:

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 11:59
by m4rcel
Yes, that one occurence in line 474 has its function_exists() around, but the second occurence in line line 494 (within the if-statement) is missing this check and thus still producing a Fatal Error ;)

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 12:11
by gouxim
m4rcel wrote:Yes, that one occurence in line 474 has its function_exists() around, but the second occurence in line line 494 (within the if-statement) is missing this check and thus still producing a Fatal Error ;)
Okay, I'm stupid :lol:
Thanks for the report, I'll update to 0.4 right away :geek:

Re: TM-WS does not work with PHP 5.2.x

Posted: 09 May 2011, 12:20
by gouxim
SDK updated, it should work know :)