mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Move some low-hanging fruit, creating new directories for the tests for * access modifiers * `class_alias()` * constant expressions * constructor property promotion * `__debugInfo()` * dereferencing * first class callable syntax Additionally, move some tests into the existing subdirectory for closure-related tests Work towards GH-15631
34 lines
475 B
PHP
34 lines
475 B
PHP
--TEST--
|
|
Closure 036: Rebinding closures, keep calling scope
|
|
--FILE--
|
|
<?php
|
|
|
|
class A {
|
|
private $x;
|
|
|
|
public function __construct($v) {
|
|
$this->x = $v;
|
|
}
|
|
|
|
public function getIncrementor() {
|
|
return function() { return ++$this->x; };
|
|
}
|
|
}
|
|
|
|
$a = new A(0);
|
|
$b = new A(10);
|
|
|
|
$ca = $a->getIncrementor();
|
|
$cb = $ca->bindTo($b);
|
|
$cb2 = Closure::bind($ca, $b);
|
|
|
|
var_dump($ca());
|
|
var_dump($cb());
|
|
var_dump($cb2());
|
|
|
|
?>
|
|
--EXPECT--
|
|
int(1)
|
|
int(11)
|
|
int(12)
|