summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2008-07-28 14:09:00 +0000
committerFelipe Pena <felipe@php.net>2008-07-28 14:09:00 +0000
commitde758769d3cf4d3f7d56cf1aae54a36d9af81461 (patch)
tree815fdbf130d45c6256843befc031c4e516817640 /Zend
parent142b3d5c921e0caad5fb2af631eaf2e0a407a2d6 (diff)
downloadphp-git-de758769d3cf4d3f7d56cf1aae54a36d9af81461.tar.gz
- New tests
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/036.phpt13
-rw-r--r--Zend/tests/037.phpt19
-rw-r--r--Zend/tests/038.phpt12
-rw-r--r--Zend/tests/closure_024.phpt16
-rw-r--r--Zend/tests/closure_025.phpt12
-rw-r--r--Zend/tests/closure_026.phpt47
-rw-r--r--Zend/tests/closure_027.phpt31
-rw-r--r--Zend/tests/closure_028.phpt14
-rw-r--r--Zend/tests/closure_029.phpt14
-rw-r--r--Zend/tests/closure_030.phpt20
-rw-r--r--Zend/tests/list_007.phpt13
-rw-r--r--Zend/tests/objects_031.phpt28
12 files changed, 239 insertions, 0 deletions
diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt
new file mode 100644
index 0000000000..6feb23f679
--- /dev/null
+++ b/Zend/tests/036.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Trying to use lambda in array offset
+--FILE--
+<?php
+
+$test[function(){}] = 1;
+$a{function() { }} = 1;
+
+?>
+--EXPECTF--
+Warning: Illegal offset type in %s on line %d
+
+Warning: Illegal offset type in %s on line %d
diff --git a/Zend/tests/037.phpt b/Zend/tests/037.phpt
new file mode 100644
index 0000000000..d7057b4844
--- /dev/null
+++ b/Zend/tests/037.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Trying to access inexistent static property of Closure
+--FILE--
+<?php
+
+namespace closure;
+
+class closure { static $x = 1;}
+
+$x = __NAMESPACE__;
+var_dump(closure::$x);
+
+var_dump($x::$x);
+
+?>
+--EXPECTF--
+int(1)
+
+Fatal error: Access to undeclared static property: Closure::$x in %s on line %d
diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt
new file mode 100644
index 0000000000..963e73f9ea
--- /dev/null
+++ b/Zend/tests/038.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Trying to use lambda as array key
+--FILE--
+<?php
+
+var_dump(array(function() { } => 1));
+
+?>
+--EXPECTF--
+Warning: Illegal offset type in %s on line %d
+array(0) {
+}
diff --git a/Zend/tests/closure_024.phpt b/Zend/tests/closure_024.phpt
new file mode 100644
index 0000000000..504e81efd9
--- /dev/null
+++ b/Zend/tests/closure_024.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Closure 024: Trying to clone the Closure object
+--FILE--
+<?php
+
+$a = function () {
+ return clone function () {
+ return 1;
+ };
+};
+
+$a();
+
+?>
+--EXPECTF--
+Fatal error: Trying to clone an uncloneable object of class Closure in %s on line %d
diff --git a/Zend/tests/closure_025.phpt b/Zend/tests/closure_025.phpt
new file mode 100644
index 0000000000..8ee187e1c8
--- /dev/null
+++ b/Zend/tests/closure_025.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Closure 025: Using closure in create_function()
+--FILE--
+<?php
+
+$a = create_function('$x', 'return function($y) use ($x) { return $x * $y; };');
+
+var_dump($a(2)->__invoke(4));
+
+?>
+--EXPECT--
+int(8)
diff --git a/Zend/tests/closure_026.phpt b/Zend/tests/closure_026.phpt
new file mode 100644
index 0000000000..235bc80514
--- /dev/null
+++ b/Zend/tests/closure_026.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Closure 026: Assigning a closure object to an array in $this
+--FILE--
+<?php
+
+class foo {
+ public function __construct() {
+ $a =& $this;
+
+ $a->a[] = function() {
+ return 1;
+ };
+
+ var_dump($this);
+
+ var_dump($this->a[0]());
+ }
+}
+
+$x = new foo;
+
+print "--------------\n";
+
+foreach ($x as $b => $c) {
+ var_dump($b, $c);
+ var_dump($c[0]());
+}
+
+?>
+--EXPECTF--
+object(foo)#%d (1) {
+ [u"a"]=>
+ array(1) {
+ [0]=>
+ object(Closure)#%d (0) {
+ }
+ }
+}
+int(1)
+--------------
+unicode(1) "a"
+array(1) {
+ [0]=>
+ object(Closure)#%d (0) {
+ }
+}
+int(1)
diff --git a/Zend/tests/closure_027.phpt b/Zend/tests/closure_027.phpt
new file mode 100644
index 0000000000..7787f729e5
--- /dev/null
+++ b/Zend/tests/closure_027.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Closure 027: Testing Closure type-hint
+--FILE--
+<?php
+
+function test(closure $a) {
+ var_dump($a());
+}
+
+
+test(function() { return new stdclass; });
+
+test(function() { });
+
+$a = function($x) use ($y) {};
+test($a);
+
+test(new stdclass);
+
+?>
+--EXPECTF--
+object(stdClass)#%d (0) {
+}
+NULL
+
+Notice: Undefined variable: y in %s on line %d
+
+Warning: Missing argument 1 for (), called in %s on line %d and defined in %s on line %d
+NULL
+
+Catchable fatal error: Argument 1 passed to test() must be an instance of Closure, instance of stdClass given, called in %s on line %d and defined in %s on line %d
diff --git a/Zend/tests/closure_028.phpt b/Zend/tests/closure_028.phpt
new file mode 100644
index 0000000000..35840755da
--- /dev/null
+++ b/Zend/tests/closure_028.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Closure 028: Trying to use lambda directly in foreach
+--FILE--
+<?php
+
+foreach (function(){ return 1; } as $y) {
+ var_dump($y);
+}
+
+print "ok\n";
+
+?>
+--EXPECT--
+ok
diff --git a/Zend/tests/closure_029.phpt b/Zend/tests/closure_029.phpt
new file mode 100644
index 0000000000..8d909c0256
--- /dev/null
+++ b/Zend/tests/closure_029.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Closure 029: Testing lambda with instanceof operator
+--FILE--
+<?php
+
+var_dump(function() { } instanceof closure);
+var_dump(function(&$x) { } instanceof closure);
+var_dump(@function(&$x) use ($y, $z) { } instanceof closure);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/closure_030.phpt b/Zend/tests/closure_030.phpt
new file mode 100644
index 0000000000..318d2150a8
--- /dev/null
+++ b/Zend/tests/closure_030.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Closure 030: Using lambda with variable variables
+--FILE--
+<?php
+
+$b = function() { return func_get_args(); };
+$a = 'b';
+var_dump($$a(1));
+var_dump($$a->__invoke(2));
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ int(1)
+}
+array(1) {
+ [0]=>
+ int(2)
+}
diff --git a/Zend/tests/list_007.phpt b/Zend/tests/list_007.phpt
new file mode 100644
index 0000000000..35a25bce65
--- /dev/null
+++ b/Zend/tests/list_007.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Using lambda with list()
+--FILE--
+<?php
+
+list($x, $y) = function() { };
+
+var_dump($x, $y);
+
+?>
+--EXPECT--
+NULL
+NULL
diff --git a/Zend/tests/objects_031.phpt b/Zend/tests/objects_031.phpt
new file mode 100644
index 0000000000..1a62a046cb
--- /dev/null
+++ b/Zend/tests/objects_031.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Cloning stdClass
+--FILE--
+<?php
+
+$x[] = clone new stdclass;
+$x[] = clone new stdclass;
+$x[] = clone new stdclass;
+
+$x[0]->a = 1;
+
+var_dump($x);
+
+?>
+--EXPECTF--
+array(3) {
+ [0]=>
+ object(stdClass)#%d (1) {
+ [u"a"]=>
+ int(1)
+ }
+ [1]=>
+ object(stdClass)#%d (0) {
+ }
+ [2]=>
+ object(stdClass)#%d (0) {
+ }
+}