473,657 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finite $_POST loops infinitely - help!

I have no idea why this is happening and I need someone to explain this
to me at the simplest level absolutely possible (pretend I'm a 10-year
old and explain it that way, please!)

This class method:

PHP Code:
/**
* Perform an array scan
*
* @access private
* @param array $array
* @see vname
*/
function &array_scan(&$a rray) {
if (is_array($arra y) && @sizeof($array) 0) {
print_r("sizeof (" . vname($array) . ") = " . sizeof($array) .
"<P>");
$index = 1;
foreach ($array as $key =$val) {
print_r("index = $index<P>"); $index++;
$this->setData($val );
print_r("key = $key and val = $val and this->data =
$this->data and array name = " . vname($array) . "<P>");
$this->scan($key, vname($array));
$array[$key] = $this->getData();
}
}
}
Constantly produces the following results:

Quote:
sizeof(_POST) = 5

index = 1

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 2

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 3

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 4

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 5

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 6

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 7

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 8

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 9

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 10

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

....// and so on and so on.. as high as 200,000 at times and still
doesn't quit!!

Why is this happening, I honestly can't see why.

Thanx
Phil

Aug 21 '06 #1
6 1379
function &array_scan(&$a rray) {
if (is_array($arra y) && @sizeof($array) 0) {
print_r("sizeof (" . vname($array) . ") = " . sizeof($array) .
"<P>");

your looping for any number higher than zero.

Flamer.

Aug 22 '06 #2
HUH??

Phil

flamer di******@hotmai l.com wrote:
function &array_scan(&$a rray) {
if (is_array($arra y) && @sizeof($array) 0) {
print_r("sizeof (" . vname($array) . ") = " . sizeof($array) .
"<P>");


your looping for any number higher than zero.

Flamer.
Aug 22 '06 #3
"comp.lang. php" <ph************ **@gmail.comwri tes:
I have no idea why this is happening and I need someone to explain this
to me at the simplest level absolutely possible (pretend I'm a 10-year
old and explain it that way, please!)

This class method:

PHP Code:
/**
* Perform an array scan
*
* @access private
* @param array $array
* @see vname
*/
function &array_scan(&$a rray) {
if (is_array($arra y) && @sizeof($array) 0) {
Instead of indenting the whole function, you may wish to just add a
premature return and negate the test:
if (!isarray ($array) || @sizeof ($array) == 0)
return;
print_r("sizeof (" . vname($array) . ") = " . sizeof($array) .
"<P>");
$index = 1;
foreach ($array as $key =$val) {
How about you just indent two more spaces after each {? This style is
very erratic and hard to read.

This appears to be your only loop; try replacing the body with something
simple like
echo "Key: $key<br />Value: $val<br /><br />\n";
and see if the problem persists.
print_r("index = $index<P>"); $index++;
$this->setData($val );
print_r("key = $key and val = $val and this->data =
$this->data and array name = " . vname($array) . "<P>");
$this->scan($key, vname($array));
$array[$key] = $this->getData();
}
}
}
Constantly produces the following results:

Quote:
sizeof(_POST) = 5

index = 1

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 2

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 3

...// and so on and so on.. as high as 200,000 at times and still
doesn't quit!!
Is $index a reserved variable, or something that foreach() might be
using internally? I assume not, but try renaming or removing it and
see if that helps any.

--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 22 '06 #4

Andrew Poelstra wrote:
"comp.lang. php" <ph************ **@gmail.comwri tes:
I have no idea why this is happening and I need someone to explain this
to me at the simplest level absolutely possible (pretend I'm a 10-year
old and explain it that way, please!)

This class method:

PHP Code:
/**
* Perform an array scan
*
* @access private
* @param array $array
* @see vname
*/
function &array_scan(&$a rray) {
if (is_array($arra y) && @sizeof($array) 0) {

Instead of indenting the whole function, you may wish to just add a
premature return and negate the test:
if (!isarray ($array) || @sizeof ($array) == 0)
return;
print_r("sizeof (" . vname($array) . ") = " . sizeof($array) .
"<P>");
$index = 1;
foreach ($array as $key =$val) {

How about you just indent two more spaces after each {? This style is
very erratic and hard to read.

This appears to be your only loop; try replacing the body with something
simple like
echo "Key: $key<br />Value: $val<br /><br />\n";
and see if the problem persists.
print_r("index = $index<P>"); $index++;
$this->setData($val );
print_r("key = $key and val = $val and this->data =
$this->data and array name = " . vname($array) . "<P>");
$this->scan($key, vname($array));
$array[$key] = $this->getData();
}
}
}
Constantly produces the following results:

Quote:
sizeof(_POST) = 5

index = 1

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 2

key = username and val = phillip and this->data = phillip and array
name = _POST

this->data = phillip

index = 3

...// and so on and so on.. as high as 200,000 at times and still
doesn't quit!!

Is $index a reserved variable, or something that foreach() might be
using internally? I assume not, but try renaming or removing it and
see if that helps any.
Well, this is what I found out:

No matter what I put within the foreach loop, the loop ran infinitely,
and this is why:

It constantly read $key as the very first element in $array, in short,
it never iterated in the first place!

This only happens when I do this;

function doStuff(&$array ) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); //
PRINTS "key = username" infinitely
}
}

--------------------------------------------------------------------------------------------------------------------------------------

What I suspect at this point that this is a PHP 4.3+ bug. I had
someone else in my DC PHP group test in PHP 5 and the loop iterated
just fine.

If I pass the array not-by-reference in PHP 4.3.9, it iterates just
fine:

function doStuff($array) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); // PRINTS
"key = username" 5 times and stops
}
}

=============== =============== =============== =============== =======

Phil
>
--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 22 '06 #5
"comp.lang. php" <ph************ **@gmail.comwri tes:
Well, this is what I found out:

No matter what I put within the foreach loop, the loop ran infinitely,
and this is why:

It constantly read $key as the very first element in $array, in short,
it never iterated in the first place!

This only happens when I do this;

function doStuff(&$array ) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); //
PRINTS "key = username" infinitely
}
}
What I suspect at this point that this is a PHP 4.3+ bug. I had
someone else in my DC PHP group test in PHP 5 and the loop iterated
just fine.
That's what it looks like. If it's not a bug, then by definition it's a
documented "feature" in PHP 4.3x, and it'll be somewhere on the site.

One of the many unfortunate aspects of a bug is that the group can't
help you, other than to suggest you upgrade your version of PHP.
If I pass the array not-by-reference in PHP 4.3.9, it iterates just
fine:
Another phrase for "not-by-reference" is "by value", FYI.
>
function doStuff($array) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); // PRINTS
"key = username" 5 times and stops
}
}
Instead of passing by reference, you could pass by value and then return
the modified version. That appears to be the best solution unless you have
the power to install PHP5.

--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 22 '06 #6

Andrew Poelstra wrote:
"comp.lang. php" <ph************ **@gmail.comwri tes:
Well, this is what I found out:

No matter what I put within the foreach loop, the loop ran infinitely,
and this is why:

It constantly read $key as the very first element in $array, in short,
it never iterated in the first place!

This only happens when I do this;

function doStuff(&$array ) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); //
PRINTS "key = username" infinitely
}
}
What I suspect at this point that this is a PHP 4.3+ bug. I had
someone else in my DC PHP group test in PHP 5 and the loop iterated
just fine.

That's what it looks like. If it's not a bug, then by definition it's a
documented "feature" in PHP 4.3x, and it'll be somewhere on the site.

One of the many unfortunate aspects of a bug is that the group can't
help you, other than to suggest you upgrade your version of PHP.
I realize this, which is probably it's an undocumented bug and will
remain that way. Someone tested this in PHP 4.3.10 and it worked
(passing array by reference and iterating through array), so perhaps
it's only in PHP 4.3.9 on back.

If I pass the array not-by-reference in PHP 4.3.9, it iterates just
fine:

Another phrase for "not-by-reference" is "by value", FYI.
Thanx, the terminology escaped me.

function doStuff($array) {
if (is_array($arra y) && @sizeof($array) 0) {
foreach ($array as $key =$val) print_r("key = $key<P>"); // PRINTS
"key = username" 5 times and stops
}
}

Instead of passing by reference, you could pass by value and then return
the modified version. That appears to be the best solution unless you have
the power to install PHP5.
That's what I wound up doing, though if you wish to change autoglobals
like $_POST or $_GET you have to remember to make sure to set it to
equal the value returned by the function or method.

Phil

PS: Thanx for your help and insight!
--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

109
4227
by: Neo | last post by:
Hi Folks,http://www.abarnett.demon.co.uk/tutorial.html#FASTFOR Page states:for( i=0; i<10; i++){ ... }i loops through the values 0,1,2,3,4,5,6,7,8,9 If you don't care about the order of the loop counter, you can do this instead: for( i=10; i--; ) { ... }Using this code, i loops through the values 9,8,7,6,5,4,3,2,1,0, and the loop should be faster. This works because it is quicker to process "i--" as the test condition, which says "is i...
2
1331
by: Toli | last post by:
I have a problem with threading in vb.net, it seems if a dll freezes or falls into an infinite loop, my multithreaded program starts allocating more threads because it cant use the frozen thread for example: declare function testit lib "test.dll" (somearg as integer) as integer dim thdTest as threading.thread sub runtest()
3
6063
by: Babak | last post by:
Hello everyone, I'm working on some Finite Elements(FE) codes in C and now I encountered some problems in assembly stage. The main idea is that a large number of 3 by 3 elemental stiffness matrices are calculated and then they should mapped to specific elements in a very big and sparse global stiffness matrix. I think the preferred storage format for the sparse matrix is Compresses Row Storage (CRS) format because it is compatible with...
67
7352
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is constantly cursing at the goto statement, accusing it of being some sort of spawn of satan. So it seems we have a pickle here. The thing is, at first thought it seems that there aren't any viable alternatives which are better suited for this...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.