nicholsr                Wed May 27 22:36:04 2009 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/tests/lang returnByReference.001.phpt 
                        returnByReference.004.phpt 
                        returnByReference.002.phpt 
                        returnByReference.006.phpt 
                        returnByReference.003.phpt 
                        returnByReference.007.phpt 
                        returnByReference.005.phpt 
                        returnByReference.009.phpt 
                        returnByReference.008.phpt 
  Log:
  Language Tests: returnByReference
  
http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.001.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.001.phpt
+++ php-src/tests/lang/returnByReference.001.phpt
--TEST--
Returning a reference from a function
--FILE--
<?php

function &returnByRef(&$arg1)
{
        return $arg1;
}

$a = 7;
$b =& returnByRef($a);
var_dump($b);
$a++;
var_dump($b);

?>
--EXPECT--
int(7)
int(8)
http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.004.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.004.phpt
+++ php-src/tests/lang/returnByReference.004.phpt
--TEST--
Returning a reference from a static method
--FILE--
<?php
Class C {
        static function returnConstantByValue() {
                return 100;
        }

        static function &returnConstantByRef() {
                return 100;
        }
        
        static function &returnVariableByRef() {
                return $GLOBALS['a'];
        }
}

echo "\n---> 1. Trying to assign by reference the return value of a function 
that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &C::returnConstantByValue();
$a++;
var_dump($a, $b);

echo "\n---> 2. Trying to assign by reference the return value of a function 
that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &C::returnConstantByRef();
$a++;
var_dump($a, $b);

echo "\n---> 3. Trying to assign by reference the return value of a function 
that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &C::returnVariableByRef();
$a++;
var_dump($a, $b);

?>
--EXPECTF--

---> 1. Trying to assign by reference the return value of a function that 
returns by value:

Strict Standards: Only variables should be assigned by reference in %s on line 
19
int(5)
int(100)

---> 2. Trying to assign by reference the return value of a function that 
returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 8
int(5)
int(100)

---> 3. Trying to assign by reference the return value of a function that 
returns by ref:
int(5)
int(5)

http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.002.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.002.phpt
+++ php-src/tests/lang/returnByReference.002.phpt
--TEST--
Returning a reference from a function.
--FILE--
<?php
function &returnRef() {
                global $a;
                return $a;
}

function returnVal() {
                global $a;
                return $a;
}

$a = "original";
$b =& returnVal();
$b = "changed";
var_dump($a); //expecting warning + "original" 

$a = "original";
$b =& returnRef();
$b = "changed";
var_dump($a); //expecting "changed" 
?>
--EXPECTF--

Strict Standards: Only variables should be assigned by reference in %s on line 
13
unicode(8) "original"
unicode(7) "changed"


http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.006.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.006.phpt
+++ php-src/tests/lang/returnByReference.006.phpt
--TEST--
Returning a reference from a function via another function
--INI--
error_reporting = E_ALL & ~E_STRICT
--FILE--
<?php
function returnConstantByValue() {
        return 100;
}

function &returnConstantByRef() {
        return 100;
}

function &returnVariableByRef() {
        return $GLOBALS['a'];
}

function &returnFunctionCallByRef($functionToCall) {
        return $functionToCall();
}

echo "\n---> 1. Via a return by ref function call, assign by reference the 
return value of a function that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &returnFunctionCallByRef('returnConstantByValue');
$a++;
var_dump($a, $b);

echo "\n---> 2. Via a return by ref function call, assign by reference the 
return value of a function that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &returnFunctionCallByRef('returnConstantByRef');
$a++;
var_dump($a, $b);

echo "\n---> 3. Via a return by ref function call, assign by reference the 
return value of a function that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &returnFunctionCallByRef('returnVariableByRef');
$a++;
var_dump($a, $b);

?>
--EXPECTF--
---> 1. Via a return by ref function call, assign by reference the return value 
of a function that returns by value:

Notice: Only variable references should be returned by reference in %s on line 
15
int(5)
int(100)

---> 2. Via a return by ref function call, assign by reference the return value 
of a function that returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 7
int(5)
int(100)

---> 3. Via a return by ref function call, assign by reference the return value 
of a function that returns by ref:
int(5)
int(5)

http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.003.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.003.phpt
+++ php-src/tests/lang/returnByReference.003.phpt
--TEST--
Returning a reference from a function
--FILE--
<?php
function returnConstantByValue() {
        return 100;
}

function &returnConstantByRef() {
        return 100;
}

function &returnVariableByRef() {
        return $GLOBALS['a'];
}

echo "\n---> 1. Trying to assign by reference the return value of a function 
that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &returnConstantByValue();
$a++;
var_dump($a, $b);

echo "\n---> 2. Trying to assign by reference the return value of a function 
that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &returnConstantByRef();
$a++;
var_dump($a, $b);

echo "\n---> 3. Trying to assign by reference the return value of a function 
that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &returnVariableByRef();
$a++;
var_dump($a, $b);

?>
--EXPECTF--

---> 1. Trying to assign by reference the return value of a function that 
returns by value:

Strict Standards: Only variables should be assigned by reference in %s on line 
17
int(5)
int(100)

---> 2. Trying to assign by reference the return value of a function that 
returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 7
int(5)
int(100)

---> 3. Trying to assign by reference the return value of a function that 
returns by ref:
int(5)
int(5)

http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.007.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.007.phpt
+++ php-src/tests/lang/returnByReference.007.phpt
--TEST--
Returning a reference from a static method via another static method
--INI--
error_reporting = E_ALL & ~E_STRICT
--FILE--
<?php
class C {
        static function returnConstantByValue() {
                return 100;
        }
        
        static function &returnConstantByRef() {
                return 100;
        }
        
        static function &returnVariableByRef() {
                return $GLOBALS['a'];
        }
        
        static function &returnFunctionCallByRef($functionToCall) {
                return C::$functionToCall();
        }
}

echo "\n---> 1. Via a return by ref function call, assign by reference the 
return value of a function that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &C::returnFunctionCallByRef('returnConstantByValue');
$a++;
var_dump($a, $b);

echo "\n---> 2. Via a return by ref function call, assign by reference the 
return value of a function that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &C::returnFunctionCallByRef('returnConstantByRef');
$a++;
var_dump($a, $b);

echo "\n---> 3. Via a return by ref function call, assign by reference the 
return value of a function that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &C::returnFunctionCallByRef('returnVariableByRef');
$a++;
var_dump($a, $b);

?>
--EXPECTF--

---> 1. Via a return by ref function call, assign by reference the return value 
of a function that returns by value:

Notice: Only variable references should be returned by reference in %s on line 
16
int(5)
int(100)

---> 2. Via a return by ref function call, assign by reference the return value 
of a function that returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 8
int(5)
int(100)

---> 3. Via a return by ref function call, assign by reference the return value 
of a function that returns by ref:
int(5)
int(5)
http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.005.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.005.phpt
+++ php-src/tests/lang/returnByReference.005.phpt
--TEST--
Returning a reference from a method
--FILE--
<?php
Class C {
        function returnConstantByValue() {
                return 100;
        }
        
        function &returnConstantByRef() {
                return 100;
        }
        
        static function &returnVariableByRef() {
                return $GLOBALS['a'];
        }
}
$c = new C;

echo "\n---> 1. Trying to assign by reference the return value of a function 
that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnConstantByValue();
$a++;
var_dump($a, $b);

echo "\n---> 2. Trying to assign by reference the return value of a function 
that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnConstantByRef();
$a++;
var_dump($a, $b);

echo "\n---> 3. Trying to assign by reference the return value of a function 
that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnVariableByRef();
$a++;
var_dump($a, $b);

?>
--EXPECTF--

---> 1. Trying to assign by reference the return value of a function that 
returns by value:

Strict Standards: Only variables should be assigned by reference in %s on line 
20
int(5)
int(100)

---> 2. Trying to assign by reference the return value of a function that 
returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 8
int(5)
int(100)

---> 3. Trying to assign by reference the return value of a function that 
returns by ref:
int(5)
int(5)

http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.009.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.009.phpt
+++ php-src/tests/lang/returnByReference.009.phpt
--TEST--
Returning a references returned by another function
--FILE--
<?php


function &returnVarByRef () {
    $b=1;
        return $b; 
}

function &testReturnVarByRef() {
        return returnVarByRef();
}

function returnVal () {
return 1; 
}

function &testReturnValByRef() {
        return returnVal();
}

echo "\n---> 1. Return a variable by reference -> No warning:\n";

var_dump (testReturnVarByRef());

echo "\n---> 2. Return a value by reference -> Warning:\n";

var_dump (testReturnValByRef());

--EXPECTF--
---> 1. Return a variable by reference -> No warning:
int(1)

---> 2. Return a value by reference -> Warning:

Notice: Only variable references should be returned by reference in %s on line 
%d
int(1)

http://cvs.php.net/viewvc.cgi/php-src/tests/lang/returnByReference.008.phpt?view=markup&rev=1.1
Index: php-src/tests/lang/returnByReference.008.phpt
+++ php-src/tests/lang/returnByReference.008.phpt
--TEST--
Returning a reference from a non-static method via another non-static method
--INI--
error_reporting = E_ALL & ~E_STRICT
--FILE--
<?php
class C {
        function returnConstantByValue() {
                return 100;
        }
        
        function &returnConstantByRef() {
                return 100;
        }
        
        function &returnVariableByRef() {
                return $GLOBALS['a'];
        }
        
        function &returnFunctionCallByRef($functionToCall) {
                return $this->$functionToCall();
        }
}
$c = new C;

echo "\n---> 1. Via a return by ref function call, assign by reference the 
return value of a function that returns by value:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnFunctionCallByRef('returnConstantByValue');
$a++;
var_dump($a, $b);

echo "\n---> 2. Via a return by ref function call, assign by reference the 
return value of a function that returns a constant by ref:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnFunctionCallByRef('returnConstantByRef');
$a++;
var_dump($a, $b);

echo "\n---> 3. Via a return by ref function call, assign by reference the 
return value of a function that returns by ref:\n";
unset($a, $b);
$a = 4;
$b = &$c->returnFunctionCallByRef('returnVariableByRef');
$a++;
var_dump($a, $b);

?>
--EXPECTF--

---> 1. Via a return by ref function call, assign by reference the return value 
of a function that returns by value:

Notice: Only variable references should be returned by reference in %s on line 
16
int(5)
int(100)

---> 2. Via a return by ref function call, assign by reference the return value 
of a function that returns a constant by ref:

Notice: Only variable references should be returned by reference in %s on line 8
int(5)
int(100)

---> 3. Via a return by ref function call, assign by reference the return value 
of a function that returns by ref:
int(5)
int(5)
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to