summaryrefslogtreecommitdiff
path: root/Zend/tests
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2011-11-06 13:25:45 +0000
committerFelipe Pena <felipe@php.net>2011-11-06 13:25:45 +0000
commiteebaaf423f98fa0340038e4350a82b97d738a355 (patch)
tree4898a1de1caf9f25a4abf0e666b142f14bb93002 /Zend/tests
parentd73b1a275d300ba8b30165dce16e273df57e3e08 (diff)
downloadphp-git-eebaaf423f98fa0340038e4350a82b97d738a355.tar.gz
- Added class member access on instantiation (e.g. (new foo)->bar()) support
Diffstat (limited to 'Zend/tests')
-rw-r--r--Zend/tests/indirect_method_call_001.phpt20
-rw-r--r--Zend/tests/indirect_method_call_002.phpt32
-rw-r--r--Zend/tests/indirect_method_call_003.phpt23
-rw-r--r--Zend/tests/indirect_method_call_004.phpt26
-rw-r--r--Zend/tests/indirect_method_call_005.phpt16
-rw-r--r--Zend/tests/indirect_property_access.phpt26
6 files changed, 143 insertions, 0 deletions
diff --git a/Zend/tests/indirect_method_call_001.phpt b/Zend/tests/indirect_method_call_001.phpt
new file mode 100644
index 0000000000..7018eaa740
--- /dev/null
+++ b/Zend/tests/indirect_method_call_001.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Testing indirect method call and exceptions
+--FILE--
+<?php
+
+class foo {
+ public function __construct() {
+ throw new Exception('foobar');
+ }
+}
+
+try {
+ $X = (new foo)->Inexistent(3);
+} catch (Exception $e) {
+ var_dump($e->getMessage()); // foobar
+}
+
+?>
+--EXPECT--
+string(6) "foobar"
diff --git a/Zend/tests/indirect_method_call_002.phpt b/Zend/tests/indirect_method_call_002.phpt
new file mode 100644
index 0000000000..1589533bdc
--- /dev/null
+++ b/Zend/tests/indirect_method_call_002.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Indirect method call with chaining
+--FILE--
+<?php
+
+class foo {
+ public $x = 'testing';
+
+ public function bar() {
+ return "foo";
+ }
+ public function baz() {
+ return new self;
+ }
+ static function xyz() {
+ }
+}
+
+var_dump((new foo())->bar()); // string(3) "foo"
+var_dump((new foo())->baz()->x); // string(7) "testing"
+var_dump((new foo())->baz()->baz()->bar()); // string(3) "foo"
+var_dump((new foo())->xyz()); // NULL
+(new foo())->www();
+
+?>
+--EXPECTF--
+string(3) "foo"
+string(7) "testing"
+string(3) "foo"
+NULL
+
+Fatal error: Call to undefined method foo::www() in %s on line %d
diff --git a/Zend/tests/indirect_method_call_003.phpt b/Zend/tests/indirect_method_call_003.phpt
new file mode 100644
index 0000000000..3df495422d
--- /dev/null
+++ b/Zend/tests/indirect_method_call_003.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Testing indirect method call
+--FILE--
+<?php
+
+class foo {
+ public $x = 1;
+
+ public function getX() {
+ return $this->x;
+ }
+ public function setX($val) {
+ $this->x = $val;
+ return $this;
+ }
+}
+
+$X = (new foo)->setX(10)->getX();
+var_dump($X); // int(10)
+
+?>
+--EXPECT--
+int(10)
diff --git a/Zend/tests/indirect_method_call_004.phpt b/Zend/tests/indirect_method_call_004.phpt
new file mode 100644
index 0000000000..689600d1f4
--- /dev/null
+++ b/Zend/tests/indirect_method_call_004.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Indirect method call and cloning
+--FILE--
+<?php
+
+
+class bar {
+ public $z;
+
+ public function __construct() {
+ $this->z = new stdclass;
+ }
+ public function getZ() {
+ return $this->z;
+ }
+}
+
+var_dump(clone (new bar)->z);
+var_dump(clone (new bar)->getZ());
+
+?>
+--EXPECTF--
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
diff --git a/Zend/tests/indirect_method_call_005.phpt b/Zend/tests/indirect_method_call_005.phpt
new file mode 100644
index 0000000000..4f4b3631c0
--- /dev/null
+++ b/Zend/tests/indirect_method_call_005.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Testing array dereferencing from instance with ArrayObject
+--FILE--
+<?php
+
+class foo extends ArrayObject {
+ public function __construct($arr) {
+ parent::__construct($arr);
+ }
+}
+
+var_dump( (new foo( array(1, array(4, 5), 3) ))[1][0] ); // int(4)
+
+?>
+--EXPECT--
+int(4)
diff --git a/Zend/tests/indirect_property_access.phpt b/Zend/tests/indirect_property_access.phpt
new file mode 100644
index 0000000000..3645687f41
--- /dev/null
+++ b/Zend/tests/indirect_property_access.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Testing indirect property access
+--FILE--
+<?php
+
+class foo {
+ public $x = 1;
+}
+
+class bar {
+ public $y = 'foo';
+}
+
+$x = 'bar';
+
+$bar = new bar;
+
+var_dump((new bar)->y); // foo
+var_dump((new $x)->y); // foo
+var_dump((new $bar->y)->x); // 1
+
+?>
+--EXPECT--
+string(3) "foo"
+string(3) "foo"
+int(1)