⚲
Project
General
Profile
Sign in
Home
Projects
Help
Search
:
TYPO3 Core
All Projects
TYPO3 Core
Overview
Activity
Roadmap
Issues
Repository
Download (807 Bytes)
Bug #20995
» test-foreach-reference-bug.php
Administrator Admin, 2009-09-21 10:21
<?
/* checks PHP behaviour on reference values in foreach loops
* by Ernesto Baschny <ernst@cron-it.de>
*/
// Test function (from t3lib_div):
function
addSlashesOnArray
(
array
&
$theArray
)
{
foreach
(
$theArray
as
&
$value
)
{
if
(
is_array
(
$value
))
{
addSlashesOnArray
(
$value
);
}
else
{
$value
=
addslashes
(
$value
);
}
#unset($value);
}
reset
(
$theArray
);
}
// create some array with multiple values
$arr
=
array
(
'a'
,
'b'
);
echo
"orig:
\n
"
;
var_dump
(
$arr
);
// apply the
addSlashesOnArray
(
$arr
);
// make a copy of the array and modify first item (we expect it to apply to copy only!):
$copy
=
$arr
;
$copy
[
0
]
=
'X'
;
// not check if original was changed by the modification in the copy:
echo
"
\n
copy:
\n
"
;
var_dump
(
$copy
);
echo
"
\n
orig (should be the same as the orig):
\n
"
;
var_dump
(
$arr
);
?>
« Previous
1
2
3
Next »
(3-3/3)
Loading...