Browse Source
Language tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
PHP-5.2.1RC1
Language tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
PHP-5.2.1RC1
32 changed files with 1514 additions and 0 deletions
-
15tests/lang/func_get_arg.001.phpt
-
19tests/lang/func_get_arg.002.phpt
-
11tests/lang/func_get_arg.003.phpt
-
16tests/lang/func_get_arg.004.phpt
-
19tests/lang/func_get_arg.005.phpt
-
23tests/lang/func_get_arg_variation.phpt
-
15tests/lang/func_get_args.001.phpt
-
22tests/lang/func_get_args.002.phpt
-
11tests/lang/func_get_args.003.phpt
-
67tests/lang/func_get_args.004.phpt
-
14tests/lang/func_num_args.001.phpt
-
14tests/lang/func_num_args.002.phpt
-
12tests/lang/func_num_args.003.phpt
-
48tests/lang/func_num_args.004.phpt
-
37tests/lang/passByReference_001.phpt
-
15tests/lang/passByReference_002.phpt
-
48tests/lang/passByReference_003.phpt
-
21tests/lang/passByReference_004.phpt
-
261tests/lang/passByReference_005.phpt
-
195tests/lang/passByReference_006.phpt
-
105tests/lang/passByReference_007.phpt
-
40tests/lang/passByReference_008.phpt
-
24tests/lang/passByReference_009.phpt
-
61tests/lang/passByReference_010.phpt
-
12tests/lang/short_tags.001.phpt
-
12tests/lang/short_tags.002.phpt
-
32tests/lang/short_tags.003.phpt
-
37tests/lang/short_tags.004.phpt
-
84tests/lang/static_basic_001.phpt
-
28tests/lang/static_basic_002.phpt
-
112tests/lang/static_variation_001.phpt
-
84tests/lang/static_variation_002.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 |
|||
@ -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) |
|||
@ -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) |
|||
@ -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) |
|||
@ -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" |
|||
@ -0,0 +1,23 @@ |
|||
--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-- |
|||
2 |
|||
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 |
|||
|
|||
@ -0,0 +1,15 @@ |
|||
--TEST-- |
|||
func_get_args with no args |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function foo() |
|||
{ |
|||
var_dump(func_get_args()); |
|||
} |
|||
foo(); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
array(0) { |
|||
} |
|||
@ -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) |
|||
} |
|||
|
|||
@ -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\) |
|||
@ -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" |
|||
@ -0,0 +1,14 @@ |
|||
--TEST-- |
|||
func_num_args with no args |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function foo() |
|||
{ |
|||
var_dump(func_num_args()); |
|||
} |
|||
foo(); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
int(0) |
|||
@ -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) |
|||
@ -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) |
|||
@ -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" |
|||
@ -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) |
|||
@ -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 |
|||
@ -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 |
|||
} |
|||
@ -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) |
|||
@ -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" |
|||
@ -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" |
|||
} |
|||
} |
|||
} |
|||
@ -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" |
|||
@ -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" |
|||
@ -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 |
|||
@ -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" |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
|
|||
@ -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 |
|||
@ -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 |
|||
@ -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) |
|||
@ -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) |
|||
} |
|||
@ -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) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue