|
|
|
@ -60,7 +60,7 @@ foreach ($scalar_variables as $scalar_var) { |
|
|
|
|
|
|
|
// destroy the variable using unset |
|
|
|
unset( $scalar_var ); |
|
|
|
// dump and see if its destroyed, expcted: NULL |
|
|
|
// dump and see if its destroyed, expcted: NULL |
|
|
|
var_dump( $scalar_var ); |
|
|
|
|
|
|
|
// check using isset to see if unset, expected: bool(false) |
|
|
|
@ -106,11 +106,11 @@ foreach ($array_variables as $array_var) { |
|
|
|
var_dump( isset($array_var['non_existent'], $array_var['none']) ); |
|
|
|
var_dump( empty($array_var['non_existent']) ); |
|
|
|
|
|
|
|
// testing empty and isset on arrays |
|
|
|
// testing empty and isset on arrays |
|
|
|
var_dump( empty($array_var) ); // expecting bool(false), except: array(), which is considered empty |
|
|
|
var_dump( isset($array_var) ); // expecting bool(true), except: array(), which is not set |
|
|
|
|
|
|
|
// get the keys of the $array_var |
|
|
|
// get the keys of the $array_var |
|
|
|
$keys = array_keys($array_var); |
|
|
|
// unset each element in the array and see the working of unset, isset & empty |
|
|
|
$inner_loop_counter = 1; |
|
|
|
@ -130,7 +130,7 @@ foreach ($array_variables as $array_var) { |
|
|
|
// calling empty, expected bool(true) |
|
|
|
var_dump( empty($array_var[$key_val]) ); |
|
|
|
|
|
|
|
// dump the array to see that that array did not get modified |
|
|
|
// dump the array to see that that array did not get modified |
|
|
|
// because of using isset, empty and unset on its element |
|
|
|
var_dump($array_var); |
|
|
|
} |
|
|
|
@ -184,11 +184,11 @@ foreach ($resources as $resource) { |
|
|
|
// now the isset() with both the args as unset |
|
|
|
var_dump( isset($resource, $temp_var) ); // expected: bool(false); |
|
|
|
|
|
|
|
// dump the resource to see if there any effect on it |
|
|
|
// dump the resource to see if there any effect on it |
|
|
|
var_dump($resource); |
|
|
|
} |
|
|
|
// unset and dump the array containing all the resources to see that |
|
|
|
// unset works correctly |
|
|
|
// unset works correctly |
|
|
|
unset($resources); |
|
|
|
var_dump($resources); |
|
|
|
var_dump( isset($resources) ); //expected: bool(false) |
|
|
|
@ -215,8 +215,8 @@ class Point |
|
|
|
} |
|
|
|
$point1 = new Point(30,40); |
|
|
|
|
|
|
|
// use unset/empty/isset to check the object |
|
|
|
var_dump($point1); // dump the object |
|
|
|
// use unset/empty/isset to check the object |
|
|
|
var_dump($point1); // dump the object |
|
|
|
|
|
|
|
// check the object and member that is not set |
|
|
|
var_dump( isset($point1) ); // expected: bool(true) |
|
|
|
@ -229,7 +229,7 @@ $point1->setLable("Point1"); |
|
|
|
var_dump( isset($point1->$lable) ); //expected: bool(true) |
|
|
|
var_dump( empty($point1->$lable) ); //expected: bool(false) |
|
|
|
|
|
|
|
// dump the object to see that obj was not harmed |
|
|
|
// dump the object to see that obj was not harmed |
|
|
|
// because of the usage of the isset & empty |
|
|
|
var_dump($point1); |
|
|
|
|
|
|
|
@ -270,11 +270,11 @@ var_dump($point2); |
|
|
|
|
|
|
|
/* testing variation in operation for isset(), empty() & unset(). |
|
|
|
Note: Most of the variation for function unset() is testing by a |
|
|
|
set of testcases named "Zend/tests/unset_cv??.phpt", only |
|
|
|
set of testcases named "Zend/tests/unset_cv??.phpt", only |
|
|
|
variation not tested are attempted here */ |
|
|
|
|
|
|
|
echo "\n*** Testing possible variation in operation for isset(), empty() & unset() ***\n"; |
|
|
|
/* unset() variation1: checking unset on static variable inside a function. |
|
|
|
/* unset() variation1: checking unset on static variable inside a function. |
|
|
|
* unset() destroys the variable only in the context of the rest of a function |
|
|
|
* Following calls will restore the previous value of a variable. |
|
|
|
*/ |
|
|
|
@ -286,14 +286,14 @@ function test_unset1() { |
|
|
|
$static_var ++; |
|
|
|
|
|
|
|
echo "value of static_var before unset: $static_var\n"; |
|
|
|
// check using isset and empty |
|
|
|
// check using isset and empty |
|
|
|
var_dump( isset($static_var) ); |
|
|
|
var_dump( empty($static_var) ); |
|
|
|
|
|
|
|
// unset the static var |
|
|
|
unset($static_var); |
|
|
|
echo "value of static_var after unset: $static_var\n"; |
|
|
|
// check using isset and empty |
|
|
|
// check using isset and empty |
|
|
|
var_dump( isset($static_var) ); |
|
|
|
var_dump( empty($static_var) ); |
|
|
|
|
|
|
|
@ -308,10 +308,10 @@ test_unset1(); |
|
|
|
|
|
|
|
|
|
|
|
echo "\n** Testing unset() variation 2: unset on a variable passed by ref. inside of a function **\n"; |
|
|
|
/* unset() variation2: Pass by reference |
|
|
|
* If a variable that is PASSED BY REFERENCE is unset() inside of a function, |
|
|
|
/* unset() variation2: Pass by reference |
|
|
|
* If a variable that is PASSED BY REFERENCE is unset() inside of a function, |
|
|
|
* only the local variable is destroyed. The variable in the calling environment |
|
|
|
* will retain the same value as before unset() was called. |
|
|
|
* will retain the same value as before unset() was called. |
|
|
|
*/ |
|
|
|
function test_unset2( &$ref_val ) { |
|
|
|
// unset the variable passed |
|
|
|
@ -341,14 +341,14 @@ $global_var = 10; |
|
|
|
function test_unset3() { |
|
|
|
global $global_var; |
|
|
|
|
|
|
|
// check the $global_var using isset and empty |
|
|
|
// check the $global_var using isset and empty |
|
|
|
var_dump( isset($global_var) ); |
|
|
|
var_dump( empty($global_var) ); |
|
|
|
|
|
|
|
// unset the global var |
|
|
|
unset($global_var); |
|
|
|
|
|
|
|
// check the $global_var using isset and empty |
|
|
|
// check the $global_var using isset and empty |
|
|
|
var_dump( isset($global_var) ); |
|
|
|
var_dump( empty($global_var) ); |
|
|
|
} |
|
|
|
|