Re: [PHP] Problems w/ goto

2010-12-20 Thread David Harkness
On Mon, Dec 20, 2010 at 7:45 PM, David Hutto  wrote:

> Is the problem with using the goto convolutedness(as I've seen other
> senior programmers in other languages when explaining, or 'showing
> off'), or is their an actual functional problem with it?


It works perfectly well and is a great solution in extremely limited cases.
The problem is that it can be used in many cases where other control flow
statements are more clear. It was more of a problem before because people
came from languages that had goto but not the other high-level control flow
statements. Using goto often leads to hard-to-follow code.

For example, rearranging the above code yields

do {
if (!acquireTarget()) {
break;
fireMainCannon();
fireMissiles();
} while (enemiesInView());

Even this doesn't get away from using break--a special form of goto for
loops. One way around that is to introduce a loop variable like $done, but I
think break is cleaner here. Sometimes goto, break, and continue are simply
the best tools for the job. I wouldn't say "never use goto," but I do feel
that 99 times out of 100 you're probably better off using something else.

One thing to keep in mind is that under the hood the PHP interpreter turns
while(), for(), etc. into a bunch of gotos.

for (  ;  ;  ) 

is just a shorter way to write


goto check;
loop:


check:
if ()
goto loop;

The same can be done for all the other control flow statements.

David


Re: [PHP] Problems w/ goto

2010-12-20 Thread David Hutto
On Mon, Dec 20, 2010 at 4:47 PM, David Harkness
 wrote:
> On Fri, Dec 17, 2010 at 10:05 AM, la...@garfieldtech.com <
> la...@garfieldtech.com> wrote:
>
>> What PHP has implemented is "named break statements", as I understand it.
>>
>
> Not exactly. You can jump to arbitrary (labeled) lines within the same
> context (method/function), but you cannot enter loop constructs--only exit
> them. While the last bit implies they are only "named break statements," you
> can use them outside of loops as a normal goto statement.
>
>    firingSequence:
>        if (!acquireTarget())
>            goto done;
>        fireMainCannon();
>        fireMissiles();
>        if (enemiesInView()):
>            goto firingSequence;
>    done:
>
> The above implements a convoluted do...while loop using goto. Recommended?

Is the problem with using the goto convolutedness(as I've seen other
senior programmers in other languages when explaining, or 'showing
off'), or is their an actual functional problem with it? Is it just
the 'sphagetti code' aspect that it can lead to, meaning confusing
another programmer? Not to hijack from the op, or dilute the
conversation any further than I did over the weekend.

> Certainly not!
>
> David
>



-- 
They're installing the breathalyzer on my email account next week.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-20 Thread David Harkness
On Fri, Dec 17, 2010 at 10:05 AM, la...@garfieldtech.com <
la...@garfieldtech.com> wrote:

> What PHP has implemented is "named break statements", as I understand it.
>

Not exactly. You can jump to arbitrary (labeled) lines within the same
context (method/function), but you cannot enter loop constructs--only exit
them. While the last bit implies they are only "named break statements," you
can use them outside of loops as a normal goto statement.

firingSequence:
if (!acquireTarget())
goto done;
fireMainCannon();
fireMissiles();
if (enemiesInView()):
goto firingSequence;
done:

The above implements a convoluted do...while loop using goto. Recommended?
Certainly not!

David


[PHP] Re: [PHP-DB] Re: [PHP] Problems w/ goto

2010-12-20 Thread David Hutto
On Mon, Dec 20, 2010 at 7:37 AM, Daniel Brown  wrote:
> On Sat, Dec 18, 2010 at 17:02, David Hutto  wrote:
>> or maybe it's saturday morning and i'm drunk?
>
>    This seems to be the most likely, and considering how all messages
> are permanently and independently archived and propagate throughout
> the Internet, it might be a good reason not to go nuts in sending
> unrelated and unintelligible messages of this nature in the future.

Yeah, that hindsights 20/20 ain't it?

>
> --
> 
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>



-- 
They're installing the breathalyzer on my email account next week.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DB] Re: [PHP] Problems w/ goto

2010-12-20 Thread Daniel Brown
On Sat, Dec 18, 2010 at 17:02, David Hutto  wrote:
> or maybe it's saturday morning and i'm drunk?

This seems to be the most likely, and considering how all messages
are permanently and independently archived and propagate throughout
the Internet, it might be a good reason not to go nuts in sending
unrelated and unintelligible messages of this nature in the future.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-18 Thread David Hutto
check out my new sig.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-18 Thread David Hutto
or maybe it's saturday morning and i'm drunk?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-18 Thread David Hutto
You approved all of us, no matter the  peer review, when you signed up
or the list. The accumulation of knowledge,
is insurmountable when delivered as a whole, but devourable if you
need satiation of appetite.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-18 Thread David Hutto
On Sat, Dec 18, 2010 at 12:45 PM, Geoffrey Bernardo Van Wyk
 wrote:
> Ethan,
>
> I tried to test your code, but I get this error next to the labels and goto
> statements:

As a 'professional' programmer, working for an entity, we deal with
these problems as we go.  As novices, we deal with it on a daily
basis. As computer scientists, we think of it as a problem already
solved, but in need of translation. Understand, buddy pal.


>
> Language feature not compatible with PHP version indicated in project
> settings
>
> I have PHP 5.3.0.
>
> Geoffrey
>
>  _
>
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: 17 December 2010 06:39 PM
> To: php-db-lists.php.net; php-general@lists.php.net
> Subject: [PHP] Problems w/ goto
>
>
>
> Dear List -
>
> I am sending this again since it does not seem to have posted.
>
> Ethan
> +++
> Dear List -
>
> Thank you with your excellent help in the past.  Here is another puzzler
>
>
> I am trying to write a program that can have two(2) independent forms
> in one PHP file.  When I run the code below [from PHP - A Beginner's
> Guide], to which I have added a second form, it freezes.  Without the
> goto statements, it runs.  When it does run, it displays both forms
> on one Web screen. What I desire is for the first form to be
> displayed, the data entered and then the second form displayed.  In
> an actual, not test program like this one, the data in the second
> form would be dependent on the first form.
>
> What did I do wrong?
>
> Thanks in advance.
>
> Here is the code:
>
> 
>     "DTD/xhtml1-transitional.dtd">
> http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
>   
>     Project 4-4: Age Calculator
>   
>   
>     Project 4-4: Age Calculator
>      // if form not yet submitted
>     // display form
>
> $ender = 0;
> begin:
>
>         if($ender == 1)
>                 exit();
>     if (!isset($_POST['dob']))
>     {
> start1:
>
> echo "  ";
> echo "  Enter your date of birth, in mm/dd/ format: ";
> echo "  ";
> echo "      ";
> echo "  ";
> echo "  ";
>
> goto begin;
>     // if form submitted
>     // process form input
>     }
> else
>     {
> starter:
> if (isset($_POST['cat']))
>         goto purr;
>       // split date value into components
>       $dateArr = explode('/', $_POST['dob']);
>
>       // calculate timestamp corresponding to date value
>       $dateTs = strtotime($_POST['dob']);
>
>       // calculate timestamp corresponding to 'today'
>       $now = strtotime('today');
>
>       // check that the value entered is in the correct format
>       if (sizeof($dateArr) != 3) {
>         die('ERROR: Please enter a valid date of birth');
>       }
>
>       // check that the value entered is a valid date
>       if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) {
>         die('ERROR: Please enter a valid date of birth');
>       }
>
>       // check that the date entered is earlier than 'today'
>       if ($dateTs >= $now) {
>         die('ERROR: Please enter a date of birth earlier than today');
>       }
>
>       // calculate difference between date of birth and today in days
>       // convert to years
>       // convert remaining days to months
>       // print output
>       $ageDays = floor(($now - $dateTs) / 86400);
>       $ageYears = floor($ageDays / 365);
>       $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
>       echo "You are approximately $ageYears years and $ageMonths months
> old.";
>       goto meow;
>  }
>
> meow:
>         if (!isset($_POST['dob']))
>                 goto begin;
>     if (!isset($_POST['cat']))
>     {
>
>
> echo "  ";
> echo "  Enter your kitten's name: ";
> echo "  ";
> echo "  ";
> echo "       Kitten\" />";
> echo "    ";
>
> }
> else
> {
> purr:
>         $name_cat = $_POST['cat'];
>
>         echo "Your Kitten is $name_cat";
>         $ender = 1;
> }
> if ($ender == 0)
>         goto begin;
> first_step:
> ?>
>
>   
> 
>
> 
>
> Ethan
>
> MySQL 5.1  PHP 5  Linux [Debian (sid)]
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>  _
>
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Problems w/ goto

2010-12-18 Thread Geoffrey Bernardo Van Wyk
Ethan,
 
I tried to test your code, but I get this error next to the labels and goto
statements:
 
Language feature not compatible with PHP version indicated in project
settings
 
I have PHP 5.3.0.
 
Geoffrey

  _  

From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: 17 December 2010 06:39 PM
To: php-db-lists.php.net; php-general@lists.php.net
Subject: [PHP] Problems w/ goto



Dear List - 

I am sending this again since it does not seem to have posted. 

Ethan 
+++ 
Dear List - 

Thank you with your excellent help in the past.  Here is another puzzler


I am trying to write a program that can have two(2) independent forms 
in one PHP file.  When I run the code below [from PHP - A Beginner's 
Guide], to which I have added a second form, it freezes.  Without the 
goto statements, it runs.  When it does run, it displays both forms 
on one Web screen. What I desire is for the first form to be 
displayed, the data entered and then the second form displayed.  In 
an actual, not test program like this one, the data in the second 
form would be dependent on the first form. 

What did I do wrong? 

Thanks in advance. 

Here is the code: 

 
 
http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> 

 Project 4-4: Age Calculator 


 Project 4-4: Age Calculator 
"; 
echo "  Enter your date of birth, in mm/dd/ format: "; 
echo "  "; 
echo "  "; 
echo "  "; 
echo "  "; 

goto begin; 
 // if form submitted 
 // process form input 
 } 
else 
 { 
starter: 
if (isset($_POST['cat'])) 
 goto purr; 
   // split date value into components 
   $dateArr = explode('/', $_POST['dob']); 

   // calculate timestamp corresponding to date value 
   $dateTs = strtotime($_POST['dob']); 

   // calculate timestamp corresponding to 'today' 
   $now = strtotime('today'); 

   // check that the value entered is in the correct format 
   if (sizeof($dateArr) != 3) { 
 die('ERROR: Please enter a valid date of birth'); 
   } 

   // check that the value entered is a valid date 
   if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { 
 die('ERROR: Please enter a valid date of birth'); 
   } 

   // check that the date entered is earlier than 'today' 
   if ($dateTs >= $now) { 
 die('ERROR: Please enter a date of birth earlier than today'); 
   } 

   // calculate difference between date of birth and today in days 
   // convert to years 
   // convert remaining days to months 
   // print output 
   $ageDays = floor(($now - $dateTs) / 86400); 
   $ageYears = floor($ageDays / 365); 
   $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); 
   echo "You are approximately $ageYears years and $ageMonths months
old."; 
   goto meow; 
  } 

meow: 
 if (!isset($_POST['dob'])) 
 goto begin; 
 if (!isset($_POST['cat'])) 
 { 


echo "  "; 
echo "  Enter your kitten's name: "; 
echo "  "; 
echo "  "; 
echo "  "; 
echo ""; 

} 
else 
{ 
purr: 
 $name_cat = $_POST['cat']; 

 echo "Your Kitten is $name_cat"; 
 $ender = 1; 
} 
if ($ender == 0) 
 goto begin; 
first_step: 
?> 


 

 

Ethan 

MySQL 5.1  PHP 5  Linux [Debian (sid)]  



-- 
PHP General Mailing List (http://www.php.net/) 
To unsubscribe, visit: http://www.php.net/unsub.php 

  _  

No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10



Re: [PHP] Problems w/ goto

2010-12-17 Thread la...@garfieldtech.com

On 12/17/10 11:57 AM, Steve Staples wrote:


I had to show the people in my office, and we all got a chuckle from teh
XKCD comic in the PHP documentation for GOTO
http://ca2.php.net/goto

Steve


I was one of the people that argued in favour of GOTO on the Internals
list a few years ago. GOTO has a use, and a very good one at that. It is
by far the most efficient construct when creating parsers or other
similar types of logic flow. The demonized GOTO of the 80s was primarily
due to jumping to arbitrary points in the code, or in the case of basic
to arbitrary line numbers in the code which had little meaning for
future readers. When used properly within a well defined scope and with
well named labels, GOTO can be a superior choice. If you think GOTO
doesn't exist in many types of software, you need only grep for it in
the C source code for PHP, MySQL, and Apache.

Cheers,
Rob.


Oh, i can see where it would be useful, i just hadn't realized it was
still in existence...   and the cartoon, was blown up, and put in my
cubical :)

RAWR!!


It's really a labeling problem.  Goto usually refers to "jump to 
arbitrary line", at least when used in the vernacular.  That's horribly 
bad and evil.


What PHP has implemented is "named break statements", as I understand 
it.  Those are not inherently evil.  It doesn't break program flow any 
more than an exception does, but it's useful for non-error-handling 
cases.  However, it reuses the keyword "goto" which is easy to confuse 
with the abomination above.


It was a rather poor choice of name, frankly.

--Larry Garfield

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-17 Thread Daniel P. Brown
On Fri, Dec 17, 2010 at 12:22, Robert Cummings  wrote:
>
> I was one of the people that argued in favour of GOTO on the Internals list
> a few years ago. GOTO has a use, and a very good one at that. It is by far
> the most efficient construct when creating parsers or other similar types of
> logic flow. The demonized GOTO of the 80s was primarily due to jumping to
> arbitrary points in the code, or in the case of basic to arbitrary line
> numbers in the code which had little meaning for future readers.

Not to mention failure to properly break, as in the OP's code example.

-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DB] Re: [PHP] Problems w/ goto

2010-12-17 Thread Daniel Brown
On Fri, Dec 17, 2010 at 12:16, Richard Quadling  wrote:
>
> And have you seen all the sad faces ...
>
> : {
>
> on http://docs.php.net/manual/en/control-structures.goto.php#92763
>
> Can't be good for them.

If only people knew how many hours - literally, hours - it took me
to keep that page clean and free from vandalism after GOTO was
introduced.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-17 Thread Steve Staples
On Fri, 2010-12-17 at 12:22 -0500, Robert Cummings wrote:
> On 10-12-17 12:08 PM, Steve Staples wrote:
> > On Fri, 2010-12-17 at 10:50 -0600, Jay Blanchard wrote:
> >> [snip]
> >> Thank you with your excellent help in the past.  Here is another
> >> puzzler
> >>
> >> I am trying to write a program that can have two(2) independent forms
> >> in one PHP file.  When I run the code below [from PHP - A Beginner's
> >> Guide], to which I have added a second form, it freezes.  Without the
> >> goto statements, it runs.  When it does run, it displays both forms
> >> on one Web screen. What I desire is for the first form to be
> >> displayed, the data entered and then the second form displayed.  In
> >> an actual, not test program like this one, the data in the second
> >> form would be dependent on the first form.
> >>
> >> What did I do wrong?
> >> [/snip]
> >>
> >> You used GOTO.
> >>
> >> In this case I would recommend using something like jQuery to 'hide' one
> >> form until the other form is complete. PHP has sent the output to the
> >> browser already, both forms are there and display when you remove the
> >> GOTO.
> >>
> >> GOTO should never be used like this.
> >>
> >> GOTO should never be used.
> >>
> >
> > Wow... that brought me back to 1990... using basic and batch files...
> > I honestly didn't even know that the GOTO was still in existence,
> > especially within PHP.
> >
> > I had to show the people in my office, and we all got a chuckle from teh
> > XKCD comic in the PHP documentation for GOTO
> > http://ca2.php.net/goto
> >
> > Steve
> 
> I was one of the people that argued in favour of GOTO on the Internals 
> list a few years ago. GOTO has a use, and a very good one at that. It is 
> by far the most efficient construct when creating parsers or other 
> similar types of logic flow. The demonized GOTO of the 80s was primarily 
> due to jumping to arbitrary points in the code, or in the case of basic 
> to arbitrary line numbers in the code which had little meaning for 
> future readers. When used properly within a well defined scope and with 
> well named labels, GOTO can be a superior choice. If you think GOTO 
> doesn't exist in many types of software, you need only grep for it in 
> the C source code for PHP, MySQL, and Apache.
> 
> Cheers,
> Rob.

Oh, i can see where it would be useful, i just hadn't realized it was
still in existence...   and the cartoon, was blown up, and put in my
cubical :)

RAWR!!


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-17 Thread Daniel Brown
On Fri, Dec 17, 2010 at 11:38, Ethan Rosenberg  wrote:
>
> I am trying to write a program that can have two(2) independent forms in one
> PHP file.  When I run the code below [from PHP - A Beginner's Guide], to
> which I have added a second form, it freezes.
[snip!]
> What did I do wrong?

You presumed that "A Beginner's Guide" meant that it was a book
for beginners not one written by a beginner.  Firstly, while GOTO
has a place in programming for certain things, the example (and I can
see the difference between the original and your additions) is
atrocious, and is not at all representative of any code you would
ever, ever want to put into production.  That looks like a nightmare
of taking a math final, not knowing the answer, and suddenly realizing
you're in your underwear --- and have explosive uncontrollable
diarrhea on top of it, and your ankles are chained to the chair.  Who
is the author?  I saw one on Amazon by Vikram Vaswani, but there was
no use of GOTO that I could find there.  I'd like to see what other
"tips" are included, or perhaps to see if that code was used in a
different context (as in, "what will work, but what not to do anyway,"
or, "I wrote this on April Fool's Day").

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-17 Thread Robert Cummings

On 10-12-17 12:08 PM, Steve Staples wrote:

On Fri, 2010-12-17 at 10:50 -0600, Jay Blanchard wrote:

[snip]
Thank you with your excellent help in the past.  Here is another
puzzler

I am trying to write a program that can have two(2) independent forms
in one PHP file.  When I run the code below [from PHP - A Beginner's
Guide], to which I have added a second form, it freezes.  Without the
goto statements, it runs.  When it does run, it displays both forms
on one Web screen. What I desire is for the first form to be
displayed, the data entered and then the second form displayed.  In
an actual, not test program like this one, the data in the second
form would be dependent on the first form.

What did I do wrong?
[/snip]

You used GOTO.

In this case I would recommend using something like jQuery to 'hide' one
form until the other form is complete. PHP has sent the output to the
browser already, both forms are there and display when you remove the
GOTO.

GOTO should never be used like this.

GOTO should never be used.



Wow... that brought me back to 1990... using basic and batch files...
I honestly didn't even know that the GOTO was still in existence,
especially within PHP.

I had to show the people in my office, and we all got a chuckle from teh
XKCD comic in the PHP documentation for GOTO
http://ca2.php.net/goto

Steve


I was one of the people that argued in favour of GOTO on the Internals 
list a few years ago. GOTO has a use, and a very good one at that. It is 
by far the most efficient construct when creating parsers or other 
similar types of logic flow. The demonized GOTO of the 80s was primarily 
due to jumping to arbitrary points in the code, or in the case of basic 
to arbitrary line numbers in the code which had little meaning for 
future readers. When used properly within a well defined scope and with 
well named labels, GOTO can be a superior choice. If you think GOTO 
doesn't exist in many types of software, you need only grep for it in 
the C source code for PHP, MySQL, and Apache.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems w/ goto

2010-12-17 Thread Nicholas Kell

On Dec 17, 2010, at 11:08 AM, Steve Staples wrote:

[snip /]

>> 
>> 
>> GOTO should never be used like this.
>> 
>> GOTO should never be used.
>> 
> 
> Wow... that brought me back to 1990... using basic and batch files...
> I honestly didn't even know that the GOTO was still in existence,
> especially within PHP.
> 
> I had to show the people in my office, and we all got a chuckle from teh
> XKCD comic in the PHP documentation for GOTO
> http://ca2.php.net/goto
> 
> Steve

I didn't know it existed in PHP either. The cartoon is priceless. I should 
probably hang that up in my office somewhere.

Re: [PHP] Problems w/ goto

2010-12-17 Thread Richard Quadling
On 17 December 2010 17:08, Steve Staples  wrote:
> On Fri, 2010-12-17 at 10:50 -0600, Jay Blanchard wrote:
>> [snip]
>> Thank you with your excellent help in the past.  Here is another
>> puzzler
>>
>> I am trying to write a program that can have two(2) independent forms
>> in one PHP file.  When I run the code below [from PHP - A Beginner's
>> Guide], to which I have added a second form, it freezes.  Without the
>> goto statements, it runs.  When it does run, it displays both forms
>> on one Web screen. What I desire is for the first form to be
>> displayed, the data entered and then the second form displayed.  In
>> an actual, not test program like this one, the data in the second
>> form would be dependent on the first form.
>>
>> What did I do wrong?
>> [/snip]
>>
>> You used GOTO.
>>
>> In this case I would recommend using something like jQuery to 'hide' one
>> form until the other form is complete. PHP has sent the output to the
>> browser already, both forms are there and display when you remove the
>> GOTO.
>>
>> GOTO should never be used like this.
>>
>> GOTO should never be used.
>>
>
> Wow... that brought me back to 1990... using basic and batch files...
> I honestly didn't even know that the GOTO was still in existence,
> especially within PHP.
>
> I had to show the people in my office, and we all got a chuckle from teh
> XKCD comic in the PHP documentation for GOTO
> http://ca2.php.net/goto
>
> Steve
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

And have you seen all the sad faces ...

: {

on http://docs.php.net/manual/en/control-structures.goto.php#92763

Can't be good for them.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Problems w/ goto

2010-12-17 Thread Steve Staples
On Fri, 2010-12-17 at 10:50 -0600, Jay Blanchard wrote:
> [snip]
> Thank you with your excellent help in the past.  Here is another
> puzzler
> 
> I am trying to write a program that can have two(2) independent forms 
> in one PHP file.  When I run the code below [from PHP - A Beginner's 
> Guide], to which I have added a second form, it freezes.  Without the 
> goto statements, it runs.  When it does run, it displays both forms 
> on one Web screen. What I desire is for the first form to be 
> displayed, the data entered and then the second form displayed.  In 
> an actual, not test program like this one, the data in the second 
> form would be dependent on the first form.
> 
> What did I do wrong?
> [/snip]
> 
> You used GOTO. 
> 
> In this case I would recommend using something like jQuery to 'hide' one
> form until the other form is complete. PHP has sent the output to the
> browser already, both forms are there and display when you remove the
> GOTO. 
> 
> GOTO should never be used like this.
> 
> GOTO should never be used.
> 

Wow... that brought me back to 1990... using basic and batch files...
I honestly didn't even know that the GOTO was still in existence,
especially within PHP.

I had to show the people in my office, and we all got a chuckle from teh
XKCD comic in the PHP documentation for GOTO
http://ca2.php.net/goto

Steve


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Problems w/ goto

2010-12-17 Thread Jay Blanchard
[snip]
Thank you with your excellent help in the past.  Here is another
puzzler

I am trying to write a program that can have two(2) independent forms 
in one PHP file.  When I run the code below [from PHP - A Beginner's 
Guide], to which I have added a second form, it freezes.  Without the 
goto statements, it runs.  When it does run, it displays both forms 
on one Web screen. What I desire is for the first form to be 
displayed, the data entered and then the second form displayed.  In 
an actual, not test program like this one, the data in the second 
form would be dependent on the first form.

What did I do wrong?
[/snip]

You used GOTO. 

In this case I would recommend using something like jQuery to 'hide' one
form until the other form is complete. PHP has sent the output to the
browser already, both forms are there and display when you remove the
GOTO. 

GOTO should never be used like this.

GOTO should never be used.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Problems w/ goto

2010-12-17 Thread Ethan Rosenberg

Dear List -

I am sending this again since it does not seem to have posted.

Ethan
+++
Dear List -

Thank you with your excellent help in the past.  Here is another puzzler

I am trying to write a program that can have two(2) independent forms 
in one PHP file.  When I run the code below [from PHP - A Beginner's 
Guide], to which I have added a second form, it freezes.  Without the 
goto statements, it runs.  When it does run, it displays both forms 
on one Web screen. What I desire is for the first form to be 
displayed, the data entered and then the second form displayed.  In 
an actual, not test program like this one, the data in the second 
form would be dependent on the first form.


What did I do wrong?

Thanks in advance.

Here is the code:



http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
  
Project 4-4: Age Calculator
  
  
Project 4-4: Age Calculator
";
echo "  Enter your date of birth, in mm/dd/ format: ";
echo "  ";
echo "  ";
echo "  ";
echo "  ";

goto begin;
// if form submitted
// process form input
}
else
{
starter:
if (isset($_POST['cat']))
goto purr;
  // split date value into components
  $dateArr = explode('/', $_POST['dob']);

  // calculate timestamp corresponding to date value
  $dateTs = strtotime($_POST['dob']);

  // calculate timestamp corresponding to 'today'
  $now = strtotime('today');

  // check that the value entered is in the correct format
  if (sizeof($dateArr) != 3) {
die('ERROR: Please enter a valid date of birth');
  }

  // check that the value entered is a valid date
  if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) {
die('ERROR: Please enter a valid date of birth');
  }

  // check that the date entered is earlier than 'today'
  if ($dateTs >= $now) {
die('ERROR: Please enter a date of birth earlier than today');
  }

  // calculate difference between date of birth and today in days
  // convert to years
  // convert remaining days to months
  // print output
  $ageDays = floor(($now - $dateTs) / 86400);
  $ageYears = floor($ageDays / 365);
  $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
  echo "You are approximately $ageYears years and $ageMonths months old.";
  goto meow;
 }

meow:
if (!isset($_POST['dob']))
goto begin;
if (!isset($_POST['cat']))
{


echo "  ";
echo "  Enter your kitten's name: ";
echo "  ";
echo "  ";
echo "  Kitten\" />";

echo "";

}
else
{
purr:
$name_cat = $_POST['cat'];

echo "Your Kitten is $name_cat";
$ender = 1;
}
if ($ender == 0)
goto begin;
first_step:
?>

  




Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)]  




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php