From: [EMAIL PROTECTED]
Operating system: RedHat Linux7
PHP version: 4.0.4pl1
PHP Bug Type: Scripting Engine problem
Bug description: Bug in foreach, reference (See Bug ID#9365, too)
I found other strange behaviors with much more simple scripts. It is very similar to
what I experienced, but it differ a little. Bug ID#9365
(I got default HTML for null output. i.e. output that
== FILE START ==
<?php
?>
== FILE END ==
script shows. These scripts do not show that.)
Here is 3 php files. (It does not have to be 3 files, but I've test with these 3 files)
- test.php (just a submission handler. Defines some functions)
- test2.php (File to be executed, when user hit submit button. Defines some functions)
- test3.php (Submit form)
Test result is written in test2.php. Please refer the comments in test2.php (Test
result is a little differ when I use multi-byte char code)
I've fund this, since I have very similar mistake in my code when I get rid of
function - refer to 1st post what I mean (Bug ID#9365) There was a variable name
collision, which I didn't care at all at that time. I passed EUC char code string
where I should pass multi-dimensional array. Fixing this solved 2nd behavior. (Note: I
still couldn't get the same behavior with these simple scripts. Fixing this bug may
fix it, too.)
Some of them are bug for sure, some error message is misleading, some might be
inevitable due to PHP's reference implementation. Some might be already reported as
bug/misbehavior.
I'll try to find out when PHP stops and restart script execution from the beginning.
This would be much more difficult, since the code does not have obvious mistake like
this one. Or is this reported as bug already? If so, please let me know.
== test.php ==
<?php
if (isset($HTTP_POST_VARS['sub_btn'])) {
include('test2.php');
exit;
}
else {
include('test3.php');
exit;
}
function pmsg(&$msg) {
foreach ($msg[1] as $v) {
print("<div class=\"error\">$v</div>\n");
}
foreach ($msg[0] as $v) {
print("<div class=\"message\">$v</div>\n");
}
}
function pmsg2(&$msg) {
while (list($k,$v) = each($msg[1])) {
print("<div class=\"error\">$v</div>\n");
}
while (list($k,$v) = each($msg[0])) {
print("<div class=\"message\">$v</div>\n");
}
}
?>
=== END test.php ===
=== test2.php ===
<html>
<head>
</head>
<body>
THIS IS TEST2.PHP<br>
<?php
// NOTE: error report level is E_ALL
$msg = 'abcd';
$msg2 = '��������������������'; // multi-byte EUC char code
$msg3 = "��������������������"; // multi-byte EUC char code
//pmsg($msg1); // <= PHP does NOT (cannot?) complains illegal pass by reference at
all.
// With $msg, IE5.5 complains "Can't find server or DNS error"
// With $msg2 or $msg3, IE5.5 just spins. It seems waiting server response. Stop
button seems does not stop operation.
// Warning: Invalid argument supplied for foreach() in .../tmp/test.php on line 12
(for unintialized var). Should complain for use of undefined var when it used.
//pmsg2($msg); // <= PHP complains "only variable can be passed by reference" as
expected.
// The same result for $msg, $msg2, $msg3
// Fatal error: Only variables can be passed by reference in .../tmp/test.php on line
21 ($msg,$msg2,$msg3)
// Warning: Variable passed to each() is not an array or object in .../tmp/test.php on
line 21 (for uninitialized var) Should complain for use of undefined var when it used.
//pmsg3($msg); // <= PHP does NOT (cannot?) complains at all like pmsg()
// With $msg IE5.5 just spins. It seems waiting server response. Stop button seems
does not stop operation.
// With $msg2 or $msg3, IE5.5 complains "Can't find server or DNS error"
// Warning: Invalid argument supplied for foreach() in ../tmp/test2.php on line xx <-
complained at inside pmsg3() (for uninitialized var) Should complain for use of
undefined var when it used.
// Note: behavior is differ from pmsg()!
//pmsg4($msg); // <= PHP complains
// Fatal error: Only variables can be passed by reference in .../tmp/test2.php on line
xx ($msg,$msg2,$msg3)
// Warning: Variable passed to each() is not an array or object in .../tmp/test2.php
on line xx <- complained at inside pmsg4() (for uninitialized var) Should complain for
use of undefined var when it used.
pmsg5($msg3); // PHP does not (cannot?) complain?
// With $msg IE5.5 just spins. It seems waiting server response. Stop button seems
does not stop operation.
// With $msg2 IE5.5 complains "Can't find server or DNS error"
// With $msg3 IE5.5 just spins. It seems waiting server response. Stop button seems
does not stop operation.
// PHP show expected error messages for undefined var.
// Note: See the difference with pmsg6().
//pmsg6($msg3); // PHP shows acceptable error messages for passing string where it
should be array.
// Fatal error: Only variables can be passed by reference in .../tmp/test2.php on line
xx <- complained at inside pmsg5 ($msg,$msg2,$msg3);
// Warning: Undefined variable: msg1 in .../tmp/test2.php on line xx (Undefined var) OK
// Warning: Variable passed to each() is not an array or object in .../tmp/test2.php
on line xx (Undefined var) OK
function pmsg3(&$msg) {
foreach ($msg[1] as $v) {
print("<div class=\"error\">$v</div>\n");
}
foreach ($msg[0] as $v) {
print("<div class=\"message\">$v</div>\n");
}
}
function pmsg4(&$msg) {
while (list($k,$v) = each($msg[1])) {
print("<div class=\"error\">$v</div>\n");
}
while (list($k,$v) = each($msg[0])) {
print("<div class=\"message\">$v</div>\n");
}
}
function pmsg5($msg) {
foreach ($msg[1] as $v) {
print("<div class=\"error\">$v</div>\n");
}
foreach ($msg[0] as $v) {
print("<div class=\"message\">$v</div>\n");
}
}
function pmsg6($msg) {
while (list($k,$v) = each($msg[1])) {
print("<div class=\"error\">$v</div>\n");
}
while (list($k,$v) = each($msg[0])) {
print("<div class=\"message\">$v</div>\n");
}
}
?>
END<br>
</body>
</html>
=== END test2.php ===
=== test3.php ===
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
</head>
<body bgcolor="#FFFFFF">
<p>THIS IS TEST3.PHP </p>
<form name="form1" method="post">
<input type="submit" name="sub_btn" value="send">
<input type="text" name="textfield">
</form>
<p>END</p>
</body>
</html>
=== END test3.php ===
--
Edit Bug report at: http://bugs.php.net/?id=9369&edit=1
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]