diff options
author | Ant Phillips <ant@php.net> | 2008-11-28 10:41:19 +0000 |
---|---|---|
committer | Ant Phillips <ant@php.net> | 2008-11-28 10:41:19 +0000 |
commit | 775389cd1d0dc08d54c17c6abac7e56d2eef9bcb (patch) | |
tree | 9c3c406032dbd86f26ce00ecc48c075fa0653d43 /tests | |
parent | ea5dd34c77aad29e783636faaabf6b361059be18 (diff) | |
download | php-git-775389cd1d0dc08d54c17c6abac7e56d2eef9bcb.tar.gz |
Language tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
Diffstat (limited to 'tests')
32 files changed, 1519 insertions, 0 deletions
diff --git a/tests/lang/func_get_arg.001.phpt b/tests/lang/func_get_arg.001.phpt new file mode 100644 index 0000000000..b1bbb18699 --- /dev/null +++ b/tests/lang/func_get_arg.001.phpt @@ -0,0 +1,15 @@ +--TEST-- +func_get_arg test +--FILE-- +<?php + +function foo($a) +{ + $a=5; + echo func_get_arg(0); +} +foo(2); +echo "\n"; +?> +--EXPECT-- +2
\ No newline at end of file diff --git a/tests/lang/func_get_arg.002.phpt b/tests/lang/func_get_arg.002.phpt new file mode 100644 index 0000000000..6ab4f95719 --- /dev/null +++ b/tests/lang/func_get_arg.002.phpt @@ -0,0 +1,19 @@ +--TEST-- +func_get_arg with variable number of args +--FILE-- +<?php + +function foo($a) +{ + $b = func_get_arg(1); + var_dump($b); + $b++; + var_dump(func_get_arg(1)); + +} +foo(2, 3); +echo "\n"; +?> +--EXPECT-- +int(3) +int(3) diff --git a/tests/lang/func_get_arg.003.phpt b/tests/lang/func_get_arg.003.phpt new file mode 100644 index 0000000000..4ef9967674 --- /dev/null +++ b/tests/lang/func_get_arg.003.phpt @@ -0,0 +1,11 @@ +--TEST-- +func_get_arg outside of a function declaration +--FILE-- +<?php + +var_dump (func_get_arg(0)); + +?> +--EXPECTF-- +Warning: func_get_arg(): Called from the global scope - no function context in %s on line %d +bool(false) diff --git a/tests/lang/func_get_arg.004.phpt b/tests/lang/func_get_arg.004.phpt new file mode 100644 index 0000000000..6931df04e6 --- /dev/null +++ b/tests/lang/func_get_arg.004.phpt @@ -0,0 +1,16 @@ +--TEST-- +func_get_arg on non-existent arg +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_get_arg(2)); +} +foo(2, 3); +echo "\n"; + +?> +--EXPECTF-- +Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d +bool(false)
\ No newline at end of file diff --git a/tests/lang/func_get_arg.005.phpt b/tests/lang/func_get_arg.005.phpt new file mode 100644 index 0000000000..e1ae78e162 --- /dev/null +++ b/tests/lang/func_get_arg.005.phpt @@ -0,0 +1,19 @@ +--TEST-- +A variable, which is referenced by another variable, is passed by value. +During the call, the original variable is updated. This should not affect func_get_arg(). +--FILE-- +<?php +function refVal($x) { + global $a; + $a = 'changed.a'; + var_dump($x); + var_dump(func_get_arg(0)); +} + +$a = "original.a"; +$ref =& $a; +refVal($a); +?> +--EXPECTF-- +string(10) "original.a" +string(10) "original.a"
\ No newline at end of file diff --git a/tests/lang/func_get_arg_variation.phpt b/tests/lang/func_get_arg_variation.phpt new file mode 100644 index 0000000000..5dd0ed63db --- /dev/null +++ b/tests/lang/func_get_arg_variation.phpt @@ -0,0 +1,28 @@ +--TEST-- +func_get_arg test +--FILE-- +<?php + +function foo($a) +{ + $a=5; + echo func_get_arg(); + echo func_get_arg(2,2); + echo func_get_arg("hello"); + echo func_get_arg(-1); + echo func_get_arg(2); +} +foo(2); +echo "\n"; +?> +--EXPECTF-- +Warning: func_get_arg() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: func_get_arg() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: func_get_arg() expects parameter 1 to be long, string given in %s on line %d + +Warning: func_get_arg(): The argument number should be >= 0 in %s on line %d + +Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d + diff --git a/tests/lang/func_get_args.001.phpt b/tests/lang/func_get_args.001.phpt new file mode 100644 index 0000000000..740a0a2165 --- /dev/null +++ b/tests/lang/func_get_args.001.phpt @@ -0,0 +1,15 @@ +--TEST-- +func_get_args with no args +--FILE-- +<?php + +function foo() +{ + var_dump(func_get_args()); +} +foo(); + +?> +--EXPECT-- +array(0) { +}
\ No newline at end of file diff --git a/tests/lang/func_get_args.002.phpt b/tests/lang/func_get_args.002.phpt new file mode 100644 index 0000000000..0a886c2f04 --- /dev/null +++ b/tests/lang/func_get_args.002.phpt @@ -0,0 +1,22 @@ +--TEST-- +func_get_args with variable number of args +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_get_args()); +} +foo(1, 2, 3); + +?> +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + diff --git a/tests/lang/func_get_args.003.phpt b/tests/lang/func_get_args.003.phpt new file mode 100644 index 0000000000..44faf7ebf8 --- /dev/null +++ b/tests/lang/func_get_args.003.phpt @@ -0,0 +1,11 @@ +--TEST-- +func_get_args() outside of a function declaration +--FILE-- +<?php + +var_dump(func_get_args()); + +?> +--EXPECTREGEX-- +Warning\: func_get_args\(\)\: Called from the global scope - no function context in \S* on line 3 +bool\(false\) diff --git a/tests/lang/func_get_args.004.phpt b/tests/lang/func_get_args.004.phpt new file mode 100644 index 0000000000..84e3ebe5a2 --- /dev/null +++ b/tests/lang/func_get_args.004.phpt @@ -0,0 +1,67 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + var_dump(func_get_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_get_args()); +} + +function refVal(&$x, $y) { + var_dump($x, $y); + var_dump(func_get_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_get_args()); +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +array(2) { + [0]=> + string(10) "original.a" + [1]=> + string(10) "original.a" +} +array(2) { + [0]=> + string(10) "original.a" + [1]=> + string(9) "changed.y" +} +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +array(2) { + [0]=> + string(10) "original.b" + [1]=> + string(10) "original.b" +} +array(2) { + [0]=> + string(9) "changed.x" + [1]=> + string(10) "original.b" +} +string(9) "changed.x"
\ No newline at end of file diff --git a/tests/lang/func_num_args.001.phpt b/tests/lang/func_num_args.001.phpt new file mode 100644 index 0000000000..c281557feb --- /dev/null +++ b/tests/lang/func_num_args.001.phpt @@ -0,0 +1,14 @@ +--TEST-- +func_num_args with no args +--FILE-- +<?php + +function foo() +{ + var_dump(func_num_args()); +} +foo(); + +?> +--EXPECT-- +int(0)
\ No newline at end of file diff --git a/tests/lang/func_num_args.002.phpt b/tests/lang/func_num_args.002.phpt new file mode 100644 index 0000000000..bfb8f7c705 --- /dev/null +++ b/tests/lang/func_num_args.002.phpt @@ -0,0 +1,14 @@ +--TEST-- +func_num_args with variable number of args +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_num_args()); +} +foo(1, 2, 3); + +?> +--EXPECT-- +int(3)
\ No newline at end of file diff --git a/tests/lang/func_num_args.003.phpt b/tests/lang/func_num_args.003.phpt new file mode 100644 index 0000000000..7cf1229bce --- /dev/null +++ b/tests/lang/func_num_args.003.phpt @@ -0,0 +1,12 @@ +--TEST-- +func_num_args() outside of a function declaration +--FILE-- +<?php + +var_dump(func_num_args()); + +?> +--EXPECTF-- + +Warning: func_num_args(): Called from the global scope - no function context in %s on line %d +int(-1)
\ No newline at end of file diff --git a/tests/lang/func_num_args.004.phpt b/tests/lang/func_num_args.004.phpt new file mode 100644 index 0000000000..8bdc6f07f6 --- /dev/null +++ b/tests/lang/func_num_args.004.phpt @@ -0,0 +1,48 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + var_dump(func_num_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_num_args()); +} + +function refVal(&$x, $y) { + var_dump($x, $y); + var_dump(func_num_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_num_args()); +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +int(2) +int(2) +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +int(2) +int(2) +string(9) "changed.x" diff --git a/tests/lang/passByReference_001.phpt b/tests/lang/passByReference_001.phpt new file mode 100644 index 0000000000..c73eacc594 --- /dev/null +++ b/tests/lang/passByReference_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +passing of function parameters by reference +--FILE-- +<?php +function f($arg1, &$arg2) +{ + var_dump($arg1++); + var_dump($arg2++); +} + +function g (&$arg1, &$arg2) +{ + var_dump($arg1); + var_dump($arg2); +} +$a = 7; +$b = 15; + +f($a, $b); + +var_dump($a); +var_dump($b); + +$c=array(1); +g($c,$c[0]); + +?> +--EXPECT-- +int(7) +int(15) +int(7) +int(16) +array(1) { + [0]=> + &int(1) +} +int(1)
\ No newline at end of file diff --git a/tests/lang/passByReference_002.phpt b/tests/lang/passByReference_002.phpt new file mode 100644 index 0000000000..d1968a3528 --- /dev/null +++ b/tests/lang/passByReference_002.phpt @@ -0,0 +1,15 @@ +--TEST-- +Attempt to pass a constant by reference +--FILE-- +<?php + +function f(&$arg1) +{ + var_dump($arg1++); +} + +f(2); + +?> +--EXPECTF-- +Fatal error: Only variables can be passed by reference in %s on line 8 diff --git a/tests/lang/passByReference_003.phpt b/tests/lang/passByReference_003.phpt new file mode 100644 index 0000000000..bbbc564654 --- /dev/null +++ b/tests/lang/passByReference_003.phpt @@ -0,0 +1,48 @@ +--TEST-- +Implicit initialisation when passing by reference +--FILE-- +<?php +function passbyVal($val) { + echo "\nInside passbyVal call:\n"; + var_dump($val); +} + +function passbyRef(&$ref) { + echo "\nInside passbyRef call:\n"; + var_dump($ref); +} + +echo "\nPassing undefined by value\n"; +passbyVal($undef1[0]); +echo "\nAfter call\n"; +var_dump($undef1); + +echo "\nPassing undefined by reference\n"; +passbyRef($undef2[0]); +echo "\nAfter call\n"; +var_dump($undef2) +?> +--EXPECTF-- + +Passing undefined by value + +Notice: Undefined variable: undef1 in %s on line 13 + +Inside passbyVal call: +NULL + +After call + +Notice: Undefined variable: undef1 in %s on line 15 +NULL + +Passing undefined by reference + +Inside passbyRef call: +NULL + +After call +array(1) { + [0]=> + NULL +} diff --git a/tests/lang/passByReference_004.phpt b/tests/lang/passByReference_004.phpt new file mode 100644 index 0000000000..e8a7963d26 --- /dev/null +++ b/tests/lang/passByReference_004.phpt @@ -0,0 +1,21 @@ +--TEST-- +passing the return value from a function by reference +--FILE-- +<?php + +function foo(&$ref) +{ + var_dump($ref); +} + +function bar($value) +{ + return $value; +} + +foo(bar(5)); + +?> +--EXPECTF-- +Strict Standards: Only variables should be passed by reference in %s on line 13 +int(5) diff --git a/tests/lang/passByReference_005.phpt b/tests/lang/passByReference_005.phpt new file mode 100644 index 0000000000..52ddeebd1c --- /dev/null +++ b/tests/lang/passByReference_005.phpt @@ -0,0 +1,261 @@ +--TEST-- +Pass uninitialised variables by reference and by value to test implicit initialisation. +--FILE-- +<?php + +function v($val) { + $val = "Val changed"; +} + +function r(&$ref) { + $ref = "Ref changed"; +} + + +function vv($val1, $val2) { + $val1 = "Val1 changed"; + $val2 = "Val2 changed"; +} + +function vr($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; +} + +function rv(&$ref, $val) { + $val = "Val changed"; + $ref = "Ref changed"; +} + +function rr(&$ref1, &$ref2) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; +} + + +class C { + + function __construct($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function v($val) { + $val = "Val changed"; + } + + function r(&$ref) { + $ref = "Ref changed"; + } + + function vv($val1, $val2) { + $val1 = "Val1 changed"; + $val2 = "Val2 changed"; + } + + function vr($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function rv(&$ref, $val) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function rr(&$ref1, &$ref2) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + } + +} + +echo "\n ---- Pass by ref / pass by val: functions ----\n"; +unset($u1, $u2); +v($u1); +r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +rr($u1, $u2); +var_dump($u1, $u2); + + +echo "\n\n ---- Pass by ref / pass by val: static method calls ----\n"; +unset($u1, $u2); +C::v($u1); +C::r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::rr($u1, $u2); +var_dump($u1, $u2); + +echo "\n\n ---- Pass by ref / pass by val: instance method calls ----\n"; +unset($u1, $u2); +$c = new C($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->v($u1); +$c->r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->rr($u1, $u2); +var_dump($u1, $u2); + +?> +--EXPECTF-- + + ---- Pass by ref / pass by val: functions ---- + +Notice: Undefined variable: u1 in %s on line 72 + +Notice: Undefined variable: u1 in %s on line 74 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 77 + +Notice: Undefined variable: u2 in %s on line 77 + +Notice: Undefined variable: u1 in %s on line 78 + +Notice: Undefined variable: u2 in %s on line 78 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 81 + +Notice: Undefined variable: u1 in %s on line 82 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 85 + +Notice: Undefined variable: u2 in %s on line 86 +string(11) "Ref changed" +NULL +string(12) "Ref1 changed" +string(12) "Ref2 changed" + + + ---- Pass by ref / pass by val: static method calls ---- + +Notice: Undefined variable: u1 in %s on line 95 + +Strict Standards: Non-static method C::v() should not be called statically in %s on line 95 + +Strict Standards: Non-static method C::r() should not be called statically in %s on line 96 + +Notice: Undefined variable: u1 in %s on line 97 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 100 + +Notice: Undefined variable: u2 in %s on line 100 + +Strict Standards: Non-static method C::vv() should not be called statically in %s on line 100 + +Notice: Undefined variable: u1 in %s on line 101 + +Notice: Undefined variable: u2 in %s on line 101 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 104 + +Strict Standards: Non-static method C::vr() should not be called statically in %s on line 104 + +Notice: Undefined variable: u1 in %s on line 105 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 108 + +Strict Standards: Non-static method C::rv() should not be called statically in %s on line 108 + +Notice: Undefined variable: u2 in %s on line 109 +string(11) "Ref changed" +NULL + +Strict Standards: Non-static method C::rr() should not be called statically in %s on line 112 +string(12) "Ref1 changed" +string(12) "Ref2 changed" + + + ---- Pass by ref / pass by val: instance method calls ---- + +Notice: Undefined variable: u1 in %s on line 117 + +Notice: Undefined variable: u1 in %s on line 118 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 121 + +Notice: Undefined variable: u1 in %s on line 123 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 126 + +Notice: Undefined variable: u2 in %s on line 126 + +Notice: Undefined variable: u1 in %s on line 127 + +Notice: Undefined variable: u2 in %s on line 127 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 130 + +Notice: Undefined variable: u1 in %s on line 131 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 134 + +Notice: Undefined variable: u2 in %s on line 135 +string(11) "Ref changed" +NULL +string(12) "Ref1 changed" +string(12) "Ref2 changed"
\ No newline at end of file diff --git a/tests/lang/passByReference_006.phpt b/tests/lang/passByReference_006.phpt new file mode 100644 index 0000000000..248be88b44 --- /dev/null +++ b/tests/lang/passByReference_006.phpt @@ -0,0 +1,195 @@ +--TEST-- +Pass uninitialised objects and arrays by reference to test implicit initialisation. +--FILE-- +<?php + +function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; +} + + +class C { + + function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; + } + + function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; + } + +} + +echo "\n ---- Pass uninitialised array & object by ref: function call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +C::refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +$c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +$c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +?> +--EXPECTF-- + + ---- Pass uninitialised array & object by ref: function call --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + ---- Pass uninitialised arrays & objects by ref: static method call --- + +Strict Standards: Non-static method C::refs() should not be called statically in %s on line 39 +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + +---- Pass uninitialised arrays & objects by ref: constructor --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + ---- Pass uninitialised arrays & objects by ref: instance method call --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +}
\ No newline at end of file diff --git a/tests/lang/passByReference_007.phpt b/tests/lang/passByReference_007.phpt new file mode 100644 index 0000000000..558ceae27e --- /dev/null +++ b/tests/lang/passByReference_007.phpt @@ -0,0 +1,105 @@ +--TEST-- +Pass function and method calls by reference and by value. +--FILE-- +<?php +class C { + static function sreturnVal() { + global $a; + return $a; + } + + static function &sreturnReference() { + global $a; + return $a; + } + + function returnVal() { + global $a; + return $a; + } + + function &returnReference() { + global $a; + return $a; + } +} + +function returnVal() { + global $a; + return $a; +} + +function &returnReference() { + global $a; + return $a; +} + + + +function foo(&$ref) { + var_dump($ref); + $ref = "changed"; +} + + +echo "Pass a function call that returns a value:\n"; +$a = "original"; +foo(returnVal()); +var_dump($a); + +echo "Pass a function call that returns a reference:\n"; +$a = "original"; +foo(returnReference()); +var_dump($a); + + +echo "\nPass a static method call that returns a value:\n"; +$a = "original"; +foo(C::sreturnVal()); +var_dump($a); + +echo "Pass a static method call that returns a reference:\n"; +$a = "original"; +foo(C::sreturnReference()); +var_dump($a); + + +$myC = new C; +echo "\nPass a method call that returns a value:\n"; +$a = "original"; +foo($myC->returnVal()); +var_dump($a); + +echo "Pass a method call that returns a reference:\n"; +$a = "original"; +foo($myC->returnReference()); +var_dump($a); + +?> +--EXPECTF-- +Pass a function call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 44 +string(8) "original" +string(8) "original" +Pass a function call that returns a reference: +string(8) "original" +string(7) "changed" + +Pass a static method call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 55 +string(8) "original" +string(8) "original" +Pass a static method call that returns a reference: +string(8) "original" +string(7) "changed" + +Pass a method call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 67 +string(8) "original" +string(8) "original" +Pass a method call that returns a reference: +string(8) "original" +string(7) "changed"
\ No newline at end of file diff --git a/tests/lang/passByReference_008.phpt b/tests/lang/passByReference_008.phpt new file mode 100644 index 0000000000..36852170bf --- /dev/null +++ b/tests/lang/passByReference_008.phpt @@ -0,0 +1,40 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + $x = 'changed.x'; + $y = 'changed.y'; +} + +function refVal(&$x, $y) { + var_dump($x, $y); + $x = 'changed.x'; + $y = 'changed.y'; +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +string(9) "changed.x"
\ No newline at end of file diff --git a/tests/lang/passByReference_009.phpt b/tests/lang/passByReference_009.phpt new file mode 100644 index 0000000000..1cbd87d6c4 --- /dev/null +++ b/tests/lang/passByReference_009.phpt @@ -0,0 +1,24 @@ +--TEST-- +Assignement as argument +--FILE-- +<?php + function foo(&$x, &$y) { $x = 1; echo $y ; } + + $x = 0; + foo($x, $x); // prints 1 .. + + + function foo2($x, &$y, $z) + { + echo $x; // 0 + echo $y; // 1 + $y = 2; + } + + $x = 0; + + foo2($x, $x, $x = 1); + echo $x; // 2 +?> +--EXPECTF-- +1012
\ No newline at end of file diff --git a/tests/lang/passByReference_010.phpt b/tests/lang/passByReference_010.phpt new file mode 100644 index 0000000000..0393cce2d1 --- /dev/null +++ b/tests/lang/passByReference_010.phpt @@ -0,0 +1,61 @@ +--TEST-- +Passing assignments by reference +--FILE-- +<?php + +function f(&$a) { + var_dump($a); + $a = "a.changed"; +} + +echo "\n\n---> Pass constant assignment by reference:\n"; +f($a="a.original"); +var_dump($a); + +echo "\n\n---> Pass variable assignment by reference:\n"; +unset($a); +$a = "a.original"; +f($b = $a); +var_dump($a); + +echo "\n\n---> Pass reference assignment by reference:\n"; +unset($a, $b); +$a = "a.original"; +f($b =& $a); +var_dump($a); + +echo "\n\n---> Pass concat assignment by reference:\n"; +unset($a, $b); +$b = "b.original"; +$a = "a.original"; +f($b .= $a); +var_dump($a); + +?> +--EXPECTF-- + + +---> Pass constant assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 9 +string(10) "a.original" +string(10) "a.original" + + +---> Pass variable assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 15 +string(10) "a.original" +string(10) "a.original" + + +---> Pass reference assignment by reference: +string(10) "a.original" +string(9) "a.changed" + + +---> Pass concat assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 28 +string(20) "b.originala.original" +string(10) "a.original" diff --git a/tests/lang/short_tags.001.phpt b/tests/lang/short_tags.001.phpt new file mode 100644 index 0000000000..79939b01a0 --- /dev/null +++ b/tests/lang/short_tags.001.phpt @@ -0,0 +1,12 @@ +--TEST-- +short tags +--INI-- +short_open_tag=on +--FILE-- +<? +echo "Used a short tag\n"; +?> +Finished +--EXPECT-- +Used a short tag +Finished diff --git a/tests/lang/short_tags.002.phpt b/tests/lang/short_tags.002.phpt new file mode 100644 index 0000000000..6f0da684ec --- /dev/null +++ b/tests/lang/short_tags.002.phpt @@ -0,0 +1,12 @@ +--TEST-- +short tags +--INI-- +short_tags=off +--FILE-- +<? +echo "Used a short tag\n"; +?> +Finished +--EXPECT-- +Used a short tag +Finished diff --git a/tests/lang/short_tags.003.phpt b/tests/lang/short_tags.003.phpt new file mode 100644 index 0000000000..64f97bcc29 --- /dev/null +++ b/tests/lang/short_tags.003.phpt @@ -0,0 +1,32 @@ +--TEST-- +tags +--INI-- +short_open_tags=on +asp_tags=on +--FILE-- +<?='this should get echoed'?> + +<%= 'so should this' %> + +<?php +$a = 'This gets echoed twice'; +?> + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + +<?php + echo "{$b}"; +?> +--EXPECT-- +this should get echoed +so should this + +This gets echoed twice +This gets echoed twice + +3 + diff --git a/tests/lang/short_tags.004.phpt b/tests/lang/short_tags.004.phpt new file mode 100644 index 0000000000..be16467e2f --- /dev/null +++ b/tests/lang/short_tags.004.phpt @@ -0,0 +1,37 @@ +--TEST-- +tags +--INI-- +short_open_tag=off +asp_tags=off +--FILE-- +<?='this should get echoed'?> + +<%= 'so should this' %> + +<?php +$a = 'This gets echoed twice'; +?> + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + +<?php + echo "{$b}"; +?> +--EXPECTF-- +<?='this should get echoed'?> + +<%= 'so should this' %> + + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + + +Notice: Undefined variable: b in %s on line %d
\ No newline at end of file diff --git a/tests/lang/static_basic_001.phpt b/tests/lang/static_basic_001.phpt new file mode 100644 index 0000000000..45fc1b2abe --- /dev/null +++ b/tests/lang/static_basic_001.phpt @@ -0,0 +1,84 @@ +--TEST-- +Static keyword - basic tests +--FILE-- +<?php + +echo "\nSame variable used as static and non static.\n"; +function staticNonStatic() { + echo "---------\n"; + $a=0; + echo "$a\n"; + static $a=10; + echo "$a\n"; + $a++; +} +staticNonStatic(); +staticNonStatic(); +staticNonStatic(); + +echo "\nLots of initialisations in the same statement.\n"; +function manyInits() { + static $counter=0; + echo "------------- Call $counter --------------\n"; + static $a, $b=10, $c=20, $d, $e=30; + echo "Unitialised : $a\n"; + echo "Initialised to 10: $b\n"; + echo "Initialised to 20: $c\n"; + echo "Unitialised : $d\n"; + echo "Initialised to 30: $e\n"; + $a++; + $b++; + $c++; + $d++; + $e++; + $counter++; +} +manyInits(); +manyInits(); +manyInits(); + +echo "\nUsing static keyword at global scope\n"; +for ($i=0; $i<3; $i++) { + static $s, $k=10; + echo "$s $k\n"; + $s++; + $k++; +} +?> +--EXPECT-- + +Same variable used as static and non static. +--------- +0 +10 +--------- +0 +11 +--------- +0 +12 + +Lots of initialisations in the same statement. +------------- Call 0 -------------- +Unitialised : +Initialised to 10: 10 +Initialised to 20: 20 +Unitialised : +Initialised to 30: 30 +------------- Call 1 -------------- +Unitialised : 1 +Initialised to 10: 11 +Initialised to 20: 21 +Unitialised : 1 +Initialised to 30: 31 +------------- Call 2 -------------- +Unitialised : 2 +Initialised to 10: 12 +Initialised to 20: 22 +Unitialised : 2 +Initialised to 30: 32 + +Using static keyword at global scope + 10 +1 11 +2 12
\ No newline at end of file diff --git a/tests/lang/static_basic_002.phpt b/tests/lang/static_basic_002.phpt new file mode 100644 index 0000000000..06e2f724ec --- /dev/null +++ b/tests/lang/static_basic_002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Multiple declarations of the same static variable +--FILE-- +<?php + +$a = 5; + +var_dump($a); + +static $a = 10; +static $a = 11; + +var_dump($a); + +function foo() { + static $a = 13; + static $a = 14; + + var_dump($a); +} + +foo(); + +?> +--EXPECT-- +int(5) +int(11) +int(14) diff --git a/tests/lang/static_variation_001.phpt b/tests/lang/static_variation_001.phpt new file mode 100644 index 0000000000..a27b9fadc7 --- /dev/null +++ b/tests/lang/static_variation_001.phpt @@ -0,0 +1,112 @@ +--TEST-- +Statics in nested functions & evals. +--FILE-- +<?php + +static $a = array(7,8,9); + +function f1() { + static $a = array(1,2,3); + + function g1() { + static $a = array(4,5,6); + var_dump($a); + } + + var_dump($a); + +} + +f1(); +g1(); +var_dump($a); + +eval(' static $b = array(10,11,12); '); + +function f2() { + eval(' static $b = array(1,2,3); '); + + function g2a() { + eval(' static $b = array(4,5,6); '); + var_dump($b); + } + + eval('function g2b() { static $b = array(7, 8, 9); var_dump($b); } '); + var_dump($b); +} + +f2(); +g2a(); +g2b(); +var_dump($b); + + +eval(' function f3() { static $c = array(1,2,3); var_dump($c); }'); +f3(); + +?> +--EXPECTF-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(10) + [1]=> + int(11) + [2]=> + int(12) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +}
\ No newline at end of file diff --git a/tests/lang/static_variation_002.phpt b/tests/lang/static_variation_002.phpt new file mode 100644 index 0000000000..b8933fd26e --- /dev/null +++ b/tests/lang/static_variation_002.phpt @@ -0,0 +1,84 @@ +--TEST-- +Static variables in methods & nested functions & evals. +--FILE-- +<?php + +Class C { + function f() { + static $a = array(1,2,3); + eval(' static $k = array(4,5,6); '); + + function cfg() { + static $a = array(7,8,9); + eval(' static $k = array(10,11,12); '); + var_dump($a, $k); + } + var_dump($a, $k); + } +} +$c = new C; +$c->f(); +cfg(); + +Class D { + static function f() { + eval('function dfg() { static $b = array(1,2,3); var_dump($b); } '); + } +} +D::f(); +dfg(); + +eval(' Class E { function f() { static $c = array(1,2,3); var_dump($c); } }'); +$e = new E; +$e->f(); + +?> +--EXPECTF-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(10) + [1]=> + int(11) + [2]=> + int(12) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +}
\ No newline at end of file |