Skip to content

Commit

Permalink
[3.0] Test for changing returning value by deferred code (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrukowski committed Jun 28, 2020
1 parent 6c57294 commit 1700096
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$finder = PhpCsFixer\Finder::create()
->in(array('src', 'tests'))
->name(array('*.php', '*.phpt'))
->notName(array('change_returned_value.phpt'))
;

$header = <<<'HEADER'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [3.0.4] - 2020-06-28

Added test for changing returned value in defer.

## [3.0.3] - 2020-06-21

Added tests for deferred exceptions.
Expand All @@ -18,6 +22,7 @@ Added additional unit test.
Order of execution deferred functions has reversed (LIFO as in Golang).
Given version is successor of version [1.0.0], to provide support for PHP ^5.3.

[3.0.4]: https://github.com/php-defer/php-defer/compare/v3.0.3...v3.0.4
[3.0.3]: https://github.com/php-defer/php-defer/compare/v3.0.2...v3.0.3
[3.0.2]: https://github.com/php-defer/php-defer/compare/v3.0.1...v3.0.2
[3.0.1]: https://github.com/php-defer/php-defer/compare/v3.0.0...v3.0.1
Expand Down
29 changes: 29 additions & 0 deletions tests/phpt/change_returned_value.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--INI--
track_errors=0
--FILE--
<?php

// example in GO https://play.golang.org/p/8RGPPPQLgQu

require \implode(\DIRECTORY_SEPARATOR, array(__DIR__, '..', '..', 'vendor', 'autoload.php'));

/**
* Function must return value by reference.
*/
function &foo()
{
// variable $result must be passed to anonymous function by reference
defer($_, function () use (&$result) {
$result = 'Change World';
});

$result = 'Hello World';

return $result;
}

echo foo();

?>
--EXPECT--
Change World

0 comments on commit 1700096

Please sign in to comment.