diff options
author | Felipe Pena <felipe@php.net> | 2008-07-14 13:39:32 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-07-14 13:39:32 +0000 |
commit | 8e4029512ad3ae24e9bdc7511a256f3524f34088 (patch) | |
tree | 217f6ffd51ada5e459dbaaade0b03750d5b2deda /Zend | |
parent | ae22f8a5d9e37c23d4f51ccc60393b37bce36d24 (diff) | |
download | php-git-8e4029512ad3ae24e9bdc7511a256f3524f34088.tar.gz |
- New tests
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/tests/closure_017.phpt | 12 | ||||
-rw-r--r-- | Zend/tests/closure_018.phpt | 28 | ||||
-rw-r--r-- | Zend/tests/closure_019.phpt | 26 | ||||
-rw-r--r-- | Zend/tests/closure_020.phpt | 36 | ||||
-rw-r--r-- | Zend/tests/closure_021.phpt | 22 |
5 files changed, 124 insertions, 0 deletions
diff --git a/Zend/tests/closure_017.phpt b/Zend/tests/closure_017.phpt new file mode 100644 index 0000000000..45a07f9441 --- /dev/null +++ b/Zend/tests/closure_017.phpt @@ -0,0 +1,12 @@ +--TEST-- +Closure 017: Trying to destroy an active lambda function +--FILE-- +<?php + +$a = function(&$a) { $a = 1; }; + +$a($a); + +?> +--EXPECTF-- +Fatal error: Cannot destroy active lambda function in %s on line %d diff --git a/Zend/tests/closure_018.phpt b/Zend/tests/closure_018.phpt new file mode 100644 index 0000000000..d98c78aeac --- /dev/null +++ b/Zend/tests/closure_018.phpt @@ -0,0 +1,28 @@ +--TEST-- +Closure 018: Assigning lambda to static var and returning by ref +--FILE-- +<?php + +class foo { + public function test(&$x) { + static $lambda; + $lambda = function &() use (&$x) { + return $x = $x * $x; + }; + return $lambda(); + } +} + +$test = new foo; + +$y = 2; +var_dump($test->test($y)); +var_dump($x = $test->test($y)); +var_dump($y, $x); + +?> +--EXPECT-- +int(4) +int(16) +int(16) +int(16) diff --git a/Zend/tests/closure_019.phpt b/Zend/tests/closure_019.phpt new file mode 100644 index 0000000000..0c4c34e163 --- /dev/null +++ b/Zend/tests/closure_019.phpt @@ -0,0 +1,26 @@ +--TEST-- +Closure 019: Calling lambda using $GLOBALS and global $var +--FILE-- +<?php + +$lambda = function &(&$x) { + return $x = $x * $x; +}; + +function test() { + global $lambda; + + $y = 3; + var_dump($GLOBALS['lambda']($y)); + var_dump($lambda($y)); + var_dump($GLOBALS['lambda'](1)); +} + +test(); + +?> +--EXPECTF-- +int(9) +int(81) + +Fatal error: Cannot pass parameter 1 by reference in %s on line %d diff --git a/Zend/tests/closure_020.phpt b/Zend/tests/closure_020.phpt new file mode 100644 index 0000000000..4143a90a40 --- /dev/null +++ b/Zend/tests/closure_020.phpt @@ -0,0 +1,36 @@ +--TEST-- +Closure 020: Trying to access private property outside class +--FILE-- +<?php + +class foo { + private $test = 3; + + public function x() { + $a = &$this; + $this->a = function() use (&$a) { return $a; }; + var_dump($this->a->__invoke()); + var_dump(is_a($this->a, 'closure')); + var_dump(is_callable($this->a)); + + return $this->a; + } +} + +$foo = new foo; +$y = $foo->x(); +var_dump($y()->test); + +?> +--EXPECTF-- +object(foo)#%d (%d) { + [u"test":u"foo":private]=> + int(3) + [u"a"]=> + object(Closure)#%d (0) { + } +} +bool(true) +bool(true) + +Fatal error: Cannot access private property foo::$test in %s on line %d diff --git a/Zend/tests/closure_021.phpt b/Zend/tests/closure_021.phpt new file mode 100644 index 0000000000..fd209cd245 --- /dev/null +++ b/Zend/tests/closure_021.phpt @@ -0,0 +1,22 @@ +--TEST-- +Closure 021: Throwing exception inside lambda +--FILE-- +<?php + +$foo = function() { + try { + throw new Exception('test!'); + } catch(Exception $e) { + throw $e; + } +}; + +try { + $foo(); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +?> +--EXPECT-- +unicode(5) "test!" |