The reference was not working.
#include <string>
#include <fstream>
#include <iostream>
#include <phpcpp.h>
using namespace std;
void swap(Php::Parameters ¶ms) {
Php::Value temp = params[0];
params[0] = params[1];
params[1] = temp;
}
extern "C"
{
PHPCPP_EXPORT void *get_module()
{
static Php::Extension extension("simple","1.0");
extension.add<swap>("swap", {
Php::ByRef("a", Php::Type::Numeric),
Php::ByRef("b", Php::Type::Numeric)
});
return extension.module();
}
}
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$a = 1;
$b = 2;
$s = swap($b, $a);
echo $a, ' ', $b, "\n";
?>
The output:
1 2
The reference was not working.
The output:
1 2