TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-20-2008, 12:33 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Big Grin lol, i made a never ending loop with arrays

i was playing around with arrays when i stumbled upon this lol

<?php

function br($num) {
for ($i=0; $i < $num;$i++) { echo "<br />"; }
}


//arrays

$fruits = array('apple','orange','banana','kiwi','plamgranit e');

while(list($key,$value) = each($fruits))

{
echo "Current:::::".br(1).current($fruits);
echo "[$key]:$value".br(1);
echo "Previous:::::".br(1).prev($fruits);

}


?>
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-20-2008, 12:37 AM   #2 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
xenon is on a distinguished road
Default

Welcome to the programming world! Wanna see something kewler? Check this out:

PHP Code:
while(true) { } 
There ya have it. The easiest infinite loop :)
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-20-2008, 12:38 AM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Default

lol, thanks
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-20-2008, 12:43 AM   #4 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Default

but if i place this exit(); between the curleys then the loop will end.

but

this cant be ended. (unless a value is changed in a variable.)

while($i != 1 && $i=0) { echo "loop<br>"; }
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-20-2008, 12:55 AM   #5 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
but if i place this exit(); between the curleys then the loop will end.
exit breaks the execution of the entire script, not just the loop. So yeah, your "implementation" of an infinite loop is so much clever (exit can be put anywhere). But what's the point of it? infinite loop = no script (aka you can't actually have a working script and also an infinite loop at the same time). So why even bother trying to create an infinite loop?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-20-2008, 12:59 AM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
exit breaks the execution of the entire script, not just the loop. So yeah, your "implementation" of an infinite loop is so much clever (exit can be put anywhere). But what's the point of it? infinite loop = no script (aka you can't actually have a working script and also an infinite loop at the same time). So why even bother trying to create an infinite loop?
its usefull to showoff the non php programmers of the cool things us newbees can make (rofl)
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-20-2008, 01:00 AM   #7 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
xenon is on a distinguished road
Default

Right...sorry for taking away your enthusiasm then...my bad
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
sarmenhb (01-20-2008)
Old 01-20-2008, 01:01 AM   #8 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Right...sorry for taking away your enthusiasm then...my bad
none taken, i just got bored lol
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-21-2008, 09:45 AM   #9 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
sketchMedia is on a distinguished road
Default

how about (my personal fav, recursive infinate loops):
PHP Code:
lol();
function 
lol()
{
    return 
lol();

or even
PHP Code:
for (;;) 
{
    echo 
'lollll';

__________________
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 12:02 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 713
Thanks: 2
Salathe is on a distinguished road
Default

Infinite loops from recursive functions/methods can be a particularly nasty trap to fall into! In a similar (erm, identical) vein to sketch's last code snippet here's another quick one-liner:
PHP Code:
for (;print 'lol';); 
__________________

Last edited by Salathe : 01-21-2008 at 12:54 PM.
Salathe is offline  
Reply With Quote
Old 01-21-2008, 01:10 PM   #11 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
sketchMedia is on a distinguished road
Default

Quote:
Infinite loops from recursive functions/methods can be a particularly nasty trap to fall into!
yep, idd it is lol.
you need to be VERY careful with recursion if you know how functions work then it should be apparent why. To cut a very long story short you risk crashing stuff as you are repeatedly calling the function thus producing function call overhead for each funcion being called, thus using up alot of memory.
__________________
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 01:54 PM   #12 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

Infinite loops are bad I crashed my computer thrice because I could not find the loop -.-
TlcAndres is offline  
Reply With Quote
Old 01-21-2008, 04:00 PM   #13 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
sketchMedia is on a distinguished road
Default

i remember a fellow student at uni do it once whilst the lab tutor was watching, luckly it didnt crash the computer, he laughed for quite a while, so did I come to think of it hehe
__________________
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 05:21 PM   #14 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default

Brilliant thread, I must say. :P
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 01-22-2008, 10:26 PM   #15 (permalink)
The Wanderer
 
Join Date: Jan 2008
Location: Nottingham
Posts: 7
Thanks: 1
Daniel is on a distinguished road
Default

PHP Code:
<?php while(phpinfo()); ?>
has to be my favourite. Plenty of information there, (p.s. No need to put an ob_start(); before that)
Send a message via MSN to Daniel
Daniel is offline  
Reply With Quote
Old 01-22-2008, 10:31 PM   #16 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,587
Thanks: 72
Wildhoney is on a distinguished road
Default

Who'd have thought such a thread would have become so popular ! You folks do surprise me sometimes.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-23-2008, 12:10 AM   #17 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Who'd have thought such a thread would have become so popular ! You folks do surprise me sometimes.
Agreed. (chars)
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 01-24-2008, 04:54 PM   #18 (permalink)
The Wanderer
 
cherries's Avatar
 
Join Date: Oct 2007
Posts: 20
Thanks: 0
cherries is an unknown quantity at this point
Default

PHP Code:
<?php while(1) print 'lol'?>
cherries is offline  
Reply With Quote
Old 01-24-2008, 09:51 PM   #19 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
sarmenhb is on a distinguished road
Default

haha, yet another popular treath by me.


Invisible Loop

for(;;) { echo "<br/>"; }
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 01-25-2008, 12:48 AM   #20 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

PHP Code:

while($total == 1)
{
   ++
$x;
   
$total = ((10 pow($x,3) + pow($x,2) + 10 $x 8) / (pow($x,2) + 1)) - 10 $x 7;
   echo (
'foo');


(don't quote me on the math, haven't tried it)
TlcAndres is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread: