summaryrefslogtreecommitdiff
path: root/Zend/tests/dereference_001.phpt
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2010-06-08 00:05:29 +0000
committerFelipe Pena <felipe@php.net>2010-06-08 00:05:29 +0000
commit99c31b31ec6103358a7f7401a9bc4a7e957637f4 (patch)
tree3cb9d89a091074c3cf4933935878a23b08384ed3 /Zend/tests/dereference_001.phpt
parentd97ae936168a24e57f55635b0113717c3bf1adeb (diff)
downloadphp-git-99c31b31ec6103358a7f7401a9bc4a7e957637f4.tar.gz
- Added array dereferencing support [DOC]
# http://wiki.php.net/rfc/functionarraydereferencing
Diffstat (limited to 'Zend/tests/dereference_001.phpt')
-rw-r--r--Zend/tests/dereference_001.phpt51
1 files changed, 51 insertions, 0 deletions
diff --git a/Zend/tests/dereference_001.phpt b/Zend/tests/dereference_001.phpt
new file mode 100644
index 0000000000..e09ad2992a
--- /dev/null
+++ b/Zend/tests/dereference_001.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Testing array dereference
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+function a() {
+ return array(1,array(5));
+}
+var_dump(a()[1][0]); // int(5)
+
+function b() {
+ return array();
+}
+var_dump(b()[0]); // Notice: Undefined offset: 0
+
+class foo {
+ public $y = 1;
+
+ public function test() {
+ return array(array(array('foobar')));
+ }
+}
+
+function c() {
+ return array(new foo);
+}
+var_dump(c()[0]->y); // int(1)
+
+function d() {
+ $obj = new foo;
+ return $obj->test();
+}
+var_dump(d()[0][0][0][3]); // string(1) "b"
+
+function e() {
+ $y = 'bar';
+ $x = array('a' => 'foo', 'b' => $y);
+ return $x;
+}
+var_dump(e()['b']); // string(3) "bar"
+
+?>
+--EXPECTF--
+int(5)
+
+Notice: Undefined offset: 0 in %s on line %d
+NULL
+int(1)
+string(1) "b"
+string(3) "bar"