Annotation of embedaddon/php/Zend/tests/closure_005.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Closure 005: Lambda inside class, lifetime of $this
3: --FILE--
4: <?php
5:
6: class A {
7: private $x;
8:
9: function __construct($x) {
10: $this->x = $x;
11: }
12:
13: function __destruct() {
14: echo "Destroyed\n";
15: }
16:
17: function getIncer($val) {
18: return function() use ($val) {
19: $this->x += $val;
20: };
21: }
22:
23: function getPrinter() {
24: return function() {
25: echo $this->x."\n";
26: };
27: }
28:
29: function getError() {
30: return static function() {
31: echo $this->x."\n";
32: };
33: }
34:
35: function printX() {
36: echo $this->x."\n";
37: }
38: }
39:
40: $a = new A(3);
41: $incer = $a->getIncer(2);
42: $printer = $a->getPrinter();
43: $error = $a->getError();
44:
45: $a->printX();
46: $printer();
47: $incer();
48: $a->printX();
49: $printer();
50:
51: unset($a);
52:
53: $incer();
54: $printer();
55:
56: unset($incer);
57: $printer();
58:
59: unset($printer);
60:
61: $error();
62:
63: echo "Done\n";
64: ?>
65: --EXPECTF--
66: 3
67: 3
68: 5
69: 5
70: 7
71: 7
72: Destroyed
73:
74: Fatal error: Using $this when not in object context in %sclosure_005.php on line 28
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>