summaryrefslogtreecommitdiff
path: root/Zend/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/tests')
-rw-r--r--Zend/tests/030.phpt38
-rw-r--r--Zend/tests/bug68370.phpt4
-rw-r--r--Zend/tests/fr47160.phpt34
-rw-r--r--Zend/tests/incompat_ctx_user.phpt11
-rw-r--r--Zend/tests/indirect_call_array_003.phpt11
-rw-r--r--Zend/tests/this_as_global.phpt12
-rw-r--r--Zend/tests/this_as_parameter.phpt11
-rw-r--r--Zend/tests/this_as_static.phpt12
-rw-r--r--Zend/tests/this_in_catch.phpt18
-rw-r--r--Zend/tests/this_in_extract.phpt17
-rw-r--r--Zend/tests/this_in_foreach_001.phpt11
-rw-r--r--Zend/tests/this_in_foreach_002.phpt11
-rw-r--r--Zend/tests/this_in_foreach_003.phpt11
-rw-r--r--Zend/tests/this_in_foreach_004.phpt11
-rw-r--r--Zend/tests/this_in_isset.phpt41
-rw-r--r--Zend/tests/this_in_mb_parse_str.phpt19
-rw-r--r--Zend/tests/this_in_parse_str.phpt17
-rw-r--r--Zend/tests/this_in_unset.phpt8
-rw-r--r--Zend/tests/this_reassign.phpt17
19 files changed, 249 insertions, 65 deletions
diff --git a/Zend/tests/030.phpt b/Zend/tests/030.phpt
index 8afcb66bd8..2318420319 100644
--- a/Zend/tests/030.phpt
+++ b/Zend/tests/030.phpt
@@ -31,40 +31,4 @@ $test->bar();
?>
--EXPECTF--
-object(Exception)#%d (7) {
- ["message":protected]=>
- string(3) "foo"
- ["string":"Exception":private]=>
- string(0) ""
- ["code":protected]=>
- int(0)
- ["file":protected]=>
- string(%d) "%s030.php"
- ["line":protected]=>
- int(%d)
- ["trace":"Exception":private]=>
- array(1) {
- [0]=>
- array(6) {
- ["file"]=>
- string(%d) "%s030.php"
- ["line"]=>
- int(%d)
- ["function"]=>
- string(3) "bar"
- ["class"]=>
- string(3) "foo"
- ["type"]=>
- string(2) "->"
- ["args"]=>
- array(0) {
- }
- }
- }
- ["previous":"Exception":private]=>
- NULL
-}
-'test' => '0'
-'test_2' => '1'
-'test_3' => '2'
-ok
+Fatal error: Cannot re-assign $this in %s030.php on line 11
diff --git a/Zend/tests/bug68370.phpt b/Zend/tests/bug68370.phpt
index 25589bf455..73411ca9b9 100644
--- a/Zend/tests/bug68370.phpt
+++ b/Zend/tests/bug68370.phpt
@@ -13,6 +13,4 @@ $x = $c->test();
print_r($x);
unset($c, $x);
--EXPECTF--
-Array
-(
-)
+Fatal error: Cannot unset $this in %sbug68370.php on line 4
diff --git a/Zend/tests/fr47160.phpt b/Zend/tests/fr47160.phpt
index ed2f15f990..786183c0c1 100644
--- a/Zend/tests/fr47160.phpt
+++ b/Zend/tests/fr47160.phpt
@@ -5,7 +5,7 @@ Calling method from array
class Hello {
public function world($x) {
- echo "Hello, $x\n"; return $this;
+ echo "Hello, $x\n";return $this;
}
}
@@ -37,8 +37,16 @@ class Magic3 {
}
$f = array('Hello','world');
-var_dump($f('you'));
-var_dump(call_user_func($f, 'you'));
+try {
+ var_dump($f('you'));
+} catch (Throwable $e) {
+ echo "Exception: " . $e->getMessage() . "\n";
+}
+try {
+ var_dump(call_user_func($f, 'you'));
+} catch (Throwable $e) {
+ echo "Exception: " . $e->getMessage() . "\n";
+}
printf("-----\n");
@@ -101,35 +109,31 @@ var_dump(call_user_func($f, 'you'));
--EXPECTF--
Deprecated: Non-static method Hello::world() should not be called statically in %s on line %d
Hello, you
-
-Notice: Undefined variable: this in %s on line %d
-NULL
+Exception: Using $this when not in object context
Deprecated: %son-static method Hello::world() should not be called statically in %s on line %d
Hello, you
-
-Notice: Undefined variable: this in %s on line %d
-NULL
+Exception: Using $this when not in object context
-----
Hello, again
-object(Hello)#1 (0) {
+object(Hello)#%d (0) {
}
Hello, again
-object(Hello)#1 (0) {
+object(Hello)#%d (0) {
}
-----
Hello, there
-object(Hello)#2 (0) {
+object(Hello)#%d (0) {
}
Hello, there
-object(Hello)#2 (0) {
+object(Hello)#%d (0) {
}
-----
Hello, devs
-object(Hello)#4 (0) {
+object(Hello)#%d (0) {
}
Hello, devs
-object(Hello)#4 (0) {
+object(Hello)#%d (0) {
}
-----
Magic::__call called (foo)!
diff --git a/Zend/tests/incompat_ctx_user.phpt b/Zend/tests/incompat_ctx_user.phpt
index f05268cee9..25c95ba219 100644
--- a/Zend/tests/incompat_ctx_user.phpt
+++ b/Zend/tests/incompat_ctx_user.phpt
@@ -10,11 +10,12 @@ class B {
function bar() { A::foo(); }
}
$b = new B;
-$b->bar();
-
+try {
+ $b->bar();
+} catch (Throwable $e) {
+ echo "Exception: " . $e->getMessage() . "\n";
+}
?>
--EXPECTF--
Deprecated: Non-static method A::foo() should not be called statically in %s on line %d
-
-Notice: Undefined variable: this in %s on line %d
-string(1) "A"
+Exception: Using $this when not in object context
diff --git a/Zend/tests/indirect_call_array_003.phpt b/Zend/tests/indirect_call_array_003.phpt
index 498c580c48..f1dde491f6 100644
--- a/Zend/tests/indirect_call_array_003.phpt
+++ b/Zend/tests/indirect_call_array_003.phpt
@@ -17,8 +17,11 @@ class foo {
}
$arr = array('foo', 'abc');
-$arr();
-
+try {
+ $arr();
+} catch (Throwable $e) {
+ echo "Exception: " . $e->getMessage() . "\n";
+}
$foo = new foo;
$arr = array($foo, 'abc');
$arr();
@@ -28,9 +31,7 @@ $arr();
--EXPECTF--
From foo::__callStatic:
string(3) "abc"
-
-Notice: Undefined variable: this in %s on line %d
-NULL
+Exception: Using $this when not in object context
From foo::__call:
string(3) "abc"
object(foo)#%d (0) {
diff --git a/Zend/tests/this_as_global.phpt b/Zend/tests/this_as_global.phpt
new file mode 100644
index 0000000000..0ba9ade1b9
--- /dev/null
+++ b/Zend/tests/this_as_global.phpt
@@ -0,0 +1,12 @@
+--TEST--
+$this as global variable
+--FILE--
+<?php
+function foo() {
+ global $this;
+ var_dump($this);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Cannot use $this as global variable in %sthis_as_global.php on line 3
diff --git a/Zend/tests/this_as_parameter.phpt b/Zend/tests/this_as_parameter.phpt
new file mode 100644
index 0000000000..93101969a7
--- /dev/null
+++ b/Zend/tests/this_as_parameter.phpt
@@ -0,0 +1,11 @@
+--TEST--
+$this as parameter
+--FILE--
+<?php
+function foo($this) {
+ var_dump($this);
+}
+foo(5);
+?>
+--EXPECTF--
+Fatal error: Cannot use $this as parameter in %sthis_as_parameter.php on line 2
diff --git a/Zend/tests/this_as_static.phpt b/Zend/tests/this_as_static.phpt
new file mode 100644
index 0000000000..f094449c12
--- /dev/null
+++ b/Zend/tests/this_as_static.phpt
@@ -0,0 +1,12 @@
+--TEST--
+$this as static variable
+--FILE--
+<?php
+function foo() {
+ static $this;
+ var_dump($this);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Cannot use $this as static variable in %sthis_as_static.php on line 3
diff --git a/Zend/tests/this_in_catch.phpt b/Zend/tests/this_in_catch.phpt
new file mode 100644
index 0000000000..d621bb18ea
--- /dev/null
+++ b/Zend/tests/this_in_catch.phpt
@@ -0,0 +1,18 @@
+--TEST--
+$this in catch
+--FILE--
+<?php
+class C {
+ function foo() {
+ try {
+ throw new Exception();
+ } catch (Exception $this) {
+ }
+ var_dump($this);
+ }
+}
+$obj = new C;
+$obj->foo();
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sthis_in_catch.php on line 6
diff --git a/Zend/tests/this_in_extract.phpt b/Zend/tests/this_in_extract.phpt
new file mode 100644
index 0000000000..de8da3d0a5
--- /dev/null
+++ b/Zend/tests/this_in_extract.phpt
@@ -0,0 +1,17 @@
+--TEST--
+$this re-assign in extract()
+--FILE--
+<?php
+function foo() {
+ extract(["this"=>42]);
+ var_dump($this);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot re-assign $this in %sthis_in_extract.php:3
+Stack trace:
+#0 %sthis_in_extract.php(3): extract(Array)
+#1 %sthis_in_extract.php(6): foo()
+#2 {main}
+ thrown in %sthis_in_extract.php on line 3
diff --git a/Zend/tests/this_in_foreach_001.phpt b/Zend/tests/this_in_foreach_001.phpt
new file mode 100644
index 0000000000..a724338b90
--- /dev/null
+++ b/Zend/tests/this_in_foreach_001.phpt
@@ -0,0 +1,11 @@
+--TEST--
+$this in foreach
+--FILE--
+<?php
+$a = [1];
+foreach ($a as $this) {
+ var_dump($this);
+}
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sthis_in_foreach_001.php on line 3
diff --git a/Zend/tests/this_in_foreach_002.phpt b/Zend/tests/this_in_foreach_002.phpt
new file mode 100644
index 0000000000..511ea36a24
--- /dev/null
+++ b/Zend/tests/this_in_foreach_002.phpt
@@ -0,0 +1,11 @@
+--TEST--
+$this in foreach
+--FILE--
+<?php
+$a = [1];
+foreach ($a as $this => $dummy) {
+ var_dump($this);
+}
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sthis_in_foreach_002.php on line 3
diff --git a/Zend/tests/this_in_foreach_003.phpt b/Zend/tests/this_in_foreach_003.phpt
new file mode 100644
index 0000000000..5f5b5ae0d8
--- /dev/null
+++ b/Zend/tests/this_in_foreach_003.phpt
@@ -0,0 +1,11 @@
+--TEST--
+$this in foreach
+--FILE--
+<?php
+$a = [1];
+foreach ($a as &$this) {
+ var_dump($this);
+}
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sthis_in_foreach_003.php on line 3
diff --git a/Zend/tests/this_in_foreach_004.phpt b/Zend/tests/this_in_foreach_004.phpt
new file mode 100644
index 0000000000..13bfbf18b4
--- /dev/null
+++ b/Zend/tests/this_in_foreach_004.phpt
@@ -0,0 +1,11 @@
+--TEST--
+$this in foreach
+--FILE--
+<?php
+$a = [[1]];
+foreach ($a as list($this)) {
+ var_dump($this);
+}
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sthis_in_foreach_004.php on line 3
diff --git a/Zend/tests/this_in_isset.phpt b/Zend/tests/this_in_isset.phpt
new file mode 100644
index 0000000000..2ae335df93
--- /dev/null
+++ b/Zend/tests/this_in_isset.phpt
@@ -0,0 +1,41 @@
+--TEST--
+$this in isset
+--FILE--
+<?php
+var_dump(isset($this));
+try {
+ var_dump(isset($this->foo));
+} catch (Throwable $e) {
+ echo "exception\n";
+}
+try {
+ var_dump(isset($this->foo->bar));
+} catch (Throwable $e) {
+ echo "exception\n";
+}
+try {
+ var_dump(isset($this[0]));
+} catch (Throwable $e) {
+ echo "exception\n";
+}
+
+class A extends ArrayObject {
+ public $foo = 5;
+ function foo() {
+ $this[0] = 5;
+ var_dump(isset($this));
+ var_dump(isset($this->foo));
+ var_dump(isset($this[0]));
+ }
+}
+$a = new A();
+$a->foo();
+?>
+--EXPECT--
+bool(false)
+exception
+exception
+exception
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/this_in_mb_parse_str.phpt b/Zend/tests/this_in_mb_parse_str.phpt
new file mode 100644
index 0000000000..8dfac94722
--- /dev/null
+++ b/Zend/tests/this_in_mb_parse_str.phpt
@@ -0,0 +1,19 @@
+--TEST--
+$this re-assign in mb_parse_str()
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+function foo() {
+ mb_parse_str("this=42");
+ var_dump($this);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot re-assign $this in %sthis_in_mb_parse_str.php:3
+Stack trace:
+#0 %sthis_in_mb_parse_str.php(3): mb_parse_str('this=42')
+#1 %sthis_in_mb_parse_str.php(6): foo()
+#2 {main}
+ thrown in %sthis_in_mb_parse_str.php on line 3
diff --git a/Zend/tests/this_in_parse_str.phpt b/Zend/tests/this_in_parse_str.phpt
new file mode 100644
index 0000000000..4540d282cc
--- /dev/null
+++ b/Zend/tests/this_in_parse_str.phpt
@@ -0,0 +1,17 @@
+--TEST--
+$this re-assign in parse_str()
+--FILE--
+<?php
+function foo() {
+ parse_str("this=42");
+ var_dump($this);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot re-assign $this in %sthis_in_parse_str.php:3
+Stack trace:
+#0 %sthis_in_parse_str.php(3): parse_str('this=42')
+#1 %sthis_in_parse_str.php(6): foo()
+#2 {main}
+ thrown in %sthis_in_parse_str.php on line 3
diff --git a/Zend/tests/this_in_unset.phpt b/Zend/tests/this_in_unset.phpt
new file mode 100644
index 0000000000..bc815049f9
--- /dev/null
+++ b/Zend/tests/this_in_unset.phpt
@@ -0,0 +1,8 @@
+--TEST--
+$this in unset
+--FILE--
+<?php
+unset($this);
+?>
+--EXPECTF--
+Fatal error: Cannot unset $this in %sthis_in_unset.php on line 2
diff --git a/Zend/tests/this_reassign.phpt b/Zend/tests/this_reassign.phpt
new file mode 100644
index 0000000000..d965ef4701
--- /dev/null
+++ b/Zend/tests/this_reassign.phpt
@@ -0,0 +1,17 @@
+--TEST--
+$this re-assign
+--FILE--
+<?php
+function foo() {
+ $a = "this";
+ $$a = 0;
+ var_dump($$a);
+}
+foo();
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot re-assign $this in %sthis_reassign.php:4
+Stack trace:
+#0 %sthis_reassign.php(7): foo()
+#1 {main}
+ thrown in %sthis_reassign.php on line 4