Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Dec 24, 2016
1 parent ba923bb commit 0ad94b2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CXX_SRC = \
test0003.cpp \
test0004.cpp \
test0005.cpp \
test0006.cpp \
issue114.cpp \
issue229.cpp \
issue234.cpp \
Expand Down
2 changes: 2 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "test0003.h"
#include "test0004.h"
#include "test0005.h"
#include "test0006.h"
#include "issue114.h"
#include "issue229.h"
#include "issue234.h"
Expand All @@ -27,6 +28,7 @@ extern "C"
init_Test0003(extension);
init_Test0004(extension);
init_Test0005(extension);
init_Test0006(extension);

init_Issue114(extension);
init_Issue229(extension);
Expand Down
41 changes: 41 additions & 0 deletions test/test0006.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <main/php.h>
#include <ostream>
#include "test0006.h"

static void test0006_1(Php::Parameters& p)
{
{
Php::Value a = 5;
a.setReferenceFlag(true);
Php::out << a.debugZval() << std::endl;

Php::Value b = Php::Value::makeReference(Php::call("returnByReference", a));

Php::out << a << " " << b << std::endl;
b = b + 1.0;
Php::out << a << " " << b << std::endl;
b = b + 1.0;
Php::out << a << " " << b << std::endl;
}

Php::out << std::endl;

{
Php::Value a = 5;
a.setReferenceFlag(true);
Php::out << a.debugZval() << std::endl;

Php::Value func("returnByReference");
Php::Value b = Php::Value::makeReference(func.operator ()(a));
Php::out << a << " " << b << std::endl;
b = b + 1.0;
Php::out << a << " " << b << std::endl;
b = b + 1.0;
Php::out << a << " " << b << std::endl;
}
}

void init_Test0006(Php::Extension& e)
{
e.add<test0006_1>("test0006_1");
}
8 changes: 8 additions & 0 deletions test/test0006.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST_TEST0006_H
#define TEST_TEST0006_H

#include "phpcpp.h"

void init_Test0006(Php::Extension& e);

#endif /* TEST_TEST0006_H */
46 changes: 46 additions & 0 deletions test/tests/0006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Test references
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
function& returnByReference(&$a)
{
return $a;
}

$a = 5;
$b = returnByReference($a);
echo $b, PHP_EOL;
++$b;
echo $a, ' ', $b, PHP_EOL;

unset($a, $b);
echo PHP_EOL;

$a = 5;
$b = &returnByReference($a);
echo $b, PHP_EOL;
++$b;
echo $a, ' ', $b, PHP_EOL;
echo PHP_EOL;

test0006_1();
?>
--EXPECT--
5
5 6

5
6 6

[type=10 refcounted=1 isref=1 refcount=1] 5
5 5
6 6
7 7

[type=10 refcounted=1 isref=1 refcount=1] 5
5 5
6 6
7 7

0 comments on commit 0ad94b2

Please sign in to comment.