Skip to content

Byref #261

Description

@ronaldoklais

The reference was not working.

#include <string>
#include <fstream>
#include <iostream>
#include <phpcpp.h>

using namespace std;

void swap(Php::Parameters &params) {
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions