FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Comments legal? For loop legal?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Comments legal? For loop legal? [message #170521] Fri, 05 November 2010 21:44 Go to next message
Brian Smither is currently offline  Brian Smither
Messages: 5
Registered: October 2010
Karma: 0
Junior Member
I'm getting T_ELSE errors and I wonder if there are issues with the
following lines of code...

// Digital Product : BEGIN

Would a colon ever constitute a beginning or ending of a script block?



for($j=0;$j<count($results);$j++) {

Would lack of white space after the semi-colons ever cause a problem?
Re: Comments legal? For loop legal? [message #170522 is a reply to message #170521] Fri, 05 November 2010 21:56 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/5/2010 5:44 PM, Brian Smither wrote:
> I'm getting T_ELSE errors and I wonder if there are issues with the
> following lines of code...
>
> // Digital Product : BEGIN
>
> Would a colon ever constitute a beginning or ending of a script block?
>
>

Not in a comment.

>
> for($j=0;$j<count($results);$j++) {
>
> Would lack of white space after the semi-colons ever cause a problem?
>
>
>

Nope, whitespace is optional here (as it is in much of PHP).

Your problem lies elsewhere - most certainly before the line the error
message is calling out. It could be a lot of things, i.e. a mismatched
single or double quote, missing braces or many other things.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Comments legal? For loop legal? [message #170523 is a reply to message #170521] Fri, 05 November 2010 22:02 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 05/11/10 21:44, Brian Smither wrote:
> I'm getting T_ELSE errors and I wonder if there are issues with the
> following lines of code...
>
> // Digital Product : BEGIN
>
> Would a colon ever constitute a beginning or ending of a script block?
>
> for($j=0;$j<count($results);$j++) {
>
> Would lack of white space after the semi-colons ever cause a problem?

If this is the line that the error is thrown out on, it's quite possible
that the error is in the preceding line(s) of code.

Also, I hope that if count($results) changes while the for loop is
executing, it does so in the manner that you expect it to?

I'd normally use:

$limit = count($results);
for($j=0;$j<$limit;$j++) {

However I don't think this will solve your problem, as I think your
problem is caused by something other than the start of this for loop.

Rgds

Denis McMahon
Re: Comments legal? For loop legal? [message #170524 is a reply to message #170521] Fri, 05 November 2010 22:28 Go to previous messageGo to next message
Brian Smither is currently offline  Brian Smither
Messages: 5
Registered: October 2010
Karma: 0
Junior Member
Brian Smither <ignore(at)ignore(dot)com> wrote in
news:Xns9E27A0232C8FFbhsmithergmailcom(at)216(dot)151(dot)153(dot)39:

> // Digital Product : BEGIN
>
> Would a colon ever constitute a beginning or ending of a script block?

This is my theory...

There is such a concept as script blocks and control blocks.

Knowing that single line comments terminate at the end of the line OR at
the end of the script block, whichever comes first. (A lot of articles
around the web neglect to mention that part.) So...

<?php
echo "Line 1";
// echo "Line 2"; ?>
die("Last Line");
<?php
echo "Line 3"; ?>

....will NOT kill the script as anticipated.

There is such a concept as an Alternative Control Structure (ACS)
syntax. Example:

if(expression):
elseif:
else:
endif;

The theory...

The ACS is acted upon in single-line comments.

Example:

if(expression):
// COMMENT : endif
else:
end; // maybe 'end' by itself is legal?

Possible result: Unexpected T_ELSE error.

NOTES:
1. Intentionally mixing structure styles can lead to unpredicable
results.
2. Inadvertently mixing structure styles, even innocuous characters in
comments, can lead to unpredicable results.
Re: Comments legal? For loop legal? [message #170525 is a reply to message #170524] Fri, 05 November 2010 22:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/5/2010 6:28 PM, Brian Smither wrote:
> Brian Smither<ignore(at)ignore(dot)com> wrote in
> news:Xns9E27A0232C8FFbhsmithergmailcom(at)216(dot)151(dot)153(dot)39:
>
>> // Digital Product : BEGIN
>>
>> Would a colon ever constitute a beginning or ending of a script block?
>
> This is my theory...
>
> There is such a concept as script blocks and control blocks.
>
> Knowing that single line comments terminate at the end of the line OR at
> the end of the script block, whichever comes first. (A lot of articles
> around the web neglect to mention that part.) So...
>

That's because you shouldn't have script block terminators in a comment.

> <?php
> echo "Line 1";
> // echo "Line 2"; ?>
> die("Last Line");
> <?php
> echo "Line 3"; ?>
>
> ...will NOT kill the script as anticipated.
>
> There is such a concept as an Alternative Control Structure (ACS)
> syntax. Example:
>

Just another way of doing the same thing.

> if(expression):
> elseif:
> else:
> endif;
>
> The theory...
>
> The ACS is acted upon in single-line comments.
>

Nope. Comments are comments

> Example:
>
> if(expression):
> // COMMENT : endif
> else:
> end; // maybe 'end' by itself is legal?
>
> Possible result: Unexpected T_ELSE error.
>

No, this will not cause such an error.

> NOTES:
> 1. Intentionally mixing structure styles can lead to unpredicable
> results.
> 2. Inadvertently mixing structure styles, even innocuous characters in
> comments, can lead to unpredicable results.
>

Nope. Results are 100% predictable, although this would not be
recommended because it would be confusing. And comments are comments -
and ignored.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Comments legal? For loop legal? [message #170531 is a reply to message #170521] Sat, 06 November 2010 16:36 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 11/5/2010 5:44 PM, Brian Smither wrote:
> I'm getting T_ELSE errors and I wonder if there are issues with the
> following lines of code...
>
> // Digital Product : BEGIN
>
> Would a colon ever constitute a beginning or ending of a script block?
>
>
>
> for($j=0;$j<count($results);$j++) {
>
> Would lack of white space after the semi-colons ever cause a problem?
>
>
>

My guess? Look for a missing "}" before the else statement for the line
indicated in the error message.

--
Shelly
Re: Comments legal? For loop legal? [message #170532 is a reply to message #170531] Sat, 06 November 2010 16:42 Go to previous message
Magno is currently offline  Magno
Messages: 49
Registered: October 2010
Karma: 0
Member
On 11/06/2010 01:36 PM, sheldonlg wrote:
> On 11/5/2010 5:44 PM, Brian Smither wrote:
>> I'm getting T_ELSE errors and I wonder if there are issues with the
>> following lines of code...
>>
>> // Digital Product : BEGIN
>>
>> Would a colon ever constitute a beginning or ending of a script block?
>>
>>
>>
>> for($j=0;$j<count($results);$j++) {
>>
>> Would lack of white space after the semi-colons ever cause a problem?
>>
>>
>>
>
> My guess? Look for a missing "}" before the else statement for the line
> indicated in the error message.
>

Right, that is the most typical reason for that error to happen.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: There is some framework/tool to generate PHP code
Next Topic: urls in php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 19:27:27 GMT 2024

Total time taken to generate the page: 0.03427 seconds