system() call causes failure
Lpsd opened this issue · 3 comments
It seems that calling system() from PHP causes things to fail in some way. Take the following example:
require_once __DIR__ . '/vendor/autoload.php';
use MultiTheftAuto\Sdk\Mta;
$input = Mta::getInput();
Mta::doReturn($input[0]);Create a basic Lua script using callRemote and call this PHP script. It simply returns the value that you passed to it (works fine).
Now try the following:
require_once __DIR__ . '/vendor/autoload.php';
use MultiTheftAuto\Sdk\Mta;
system("ls");
$input = Mta::getInput();
Mta::doReturn($input[0]);This will result in failure, and return nil instead of the value you passed to callRemote.
As a note, this issue was present in the previous version of the PHP SDK.
Did you check the PHP response outside MTA?
MTA needs a JSON to parse it as function arguments but the function system, as the page says, display the output "polluting" the JSON that Mta::doReturn() prints.
On the other hand, exec has the same function but omitting the print. That's why change system to exec is a solution.
Noted, I didn't realise that system is actually outputting stuff. Sorry!
No problem!