Log in

View Full Version : Resolved Parse Error



marain
01-06-2021, 07:58 PM
Esteemed PHP'ers:

My PHP parser was quite happy with this statement:


echo "<br /><br />Your final quota of hands for this session was " . $numbers [$_SESSION["limit"]] . ". This would have been hand number " . $numbers [min (($_SESSION["bigCounter"] + 1), count ($numbers) - 1)] . ". BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from " . $excuses [(rand(0, count($excuses) - 1))] . ". She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

In an effort to make this statement more elegant, I attempted interpolation:


echo "<br /><br />Your final quota of hands for this session was $numbers [$_SESSION['limit']]. This would have been hand number $numbers [min (($_SESSION['bigCounter'] + 1), count ($numbers) - 1)]. For that reason, we must deny at the moment your efforts for a new hand. We deny this new hand with respect and with love. BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from $excuses [(rand(0, count($excuses) - 1))]. She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

My efforts resulted in this message:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/marainla/public_html/pageContent/q-genp.txt on line 438

On a hunch, I tried escaping some of the periods:


echo "<br /><br />Your final quota of hands for this session was $numbers [$_SESSION['limit']]\. This would have been hand number $numbers [min (($_SESSION['bigCounter'] + 1), count ($numbers) - 1)]\. For that reason, we must deny at the moment your efforts for a new hand. We deny this new hand with respect and with love. BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from $excuses [(rand(0, count($excuses) - 1))]\. She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

That change generated the same error message.

Next I tried eliminating some white space:



echo "<br /><br />Your final quota of hands for this session was $numbers[$_SESSION['limit']]. This would have been hand number $numbers[min(($_SESSION['bigCounter']+1),count($numbers)-1)]. For that reason, we must deny at the moment your efforts for a new hand. We deny this new hand with respect and with love. BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from $excuses[(rand(0, count($excuses)-1))]. She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

and got...

Parse error: syntax error, unexpected '[', expecting ']' in /home/marainla/public_html/pageContent/q-genp.txt on line 438

Might someone please assist me in my quest for elegance?

A.

coothead
01-06-2021, 09:02 PM
Hi there marain,


I am not a PHP expert, but I believe that this amended code...



echo "<br><br>
Your final quota of hands for this session was "
. $numbers [$_SESSION['limit']] .
". This would have been hand number "
. $numbers [min (($_SESSION['bigCounter'] + 1), count ($numbers) - 1)] . "
. For that reason, we must deny at the moment your efforts
for a new hand. We deny this new hand with respect and with love. BUT do not
despair: You can begin a <i>new</i> session when our web-mistress returns from"
. $excuses [(rand(0, count($excuses) - 1))] . ". She should be coming back in
a while. When she does, it will make her so happy if you are here. We hope you
will not disappoint her. She will cheerfully review your starting quota of poker
hands and, if necessary, adjust it.<br><br>
So hang out or, if necessary, come back later. Or feel free to refresh your
<i>quotation</i>, above. You can do that while waiting!";

...will get you going again. :D


coothead

marain
01-06-2021, 09:26 PM
Coothead,

My initial inquiry was somewhat misleading. The page presently runs, using the original ineligant code. I'm just trying to use interpolation to make the code easier to read.

coothead
01-06-2021, 09:35 PM
Hi there marain,


is the code that I posted not easier to read? :confused:

Perhaps we're not singing from the same hymn sheet. :(


coothead

marain
01-06-2021, 09:55 PM
Coothead,

It is indeed easier to read, and I thank you--I'm not one to look a gift horse in the mouth ;-) . My quest, however, is for interpolation that I believe will enable elimination of all internal quotation marks, leaving just the beginning and ending quotation marks. That, I believe, would be code easier still to read. My subsequent examples satisfy that quest. That's the good news. The bad news is that that new elegant code does not work.

coothead
01-06-2021, 10:07 PM
My quest, however, is for interpolation that I believe will enable
elimination of all internal quotation marks, leaving just the
beginning and ending quotation marks.


I'm afraid, that's not possible.

But, as I have pointed out, I am not a PHP expert.


coothead

marain
01-06-2021, 10:42 PM
Coothead,

You get an "A" for effort!

Perhaps someone here who is an expert can educate both of us ;-)

A.

coothead
01-07-2021, 12:10 AM
Hi there marain,


If a PHP guru is not forthcoming here then,
take your query to this forum...

https://forums.cutcodedown.com


coothead

marain
01-07-2021, 01:34 AM
Many thanks, Coothead.

I'll linger here for a while..we've given it now well less than half a day!

marain
01-07-2021, 02:51 PM
Modified the statement. Still it fails the syntax check, but I believe I'm making progress.

The modification was to put the interpolated variables into braces ( { and } ). The statement now looks like this:


echo "<br /><br />Your final quota of hands for this session was {$numbers[$_SESSION['limit']]}. This would have been hand number {$numbers[min(($_SESSION['bigCounter']+1),count($numbers)-1)]}. For that reason, we must deny at the moment your efforts for a new hand. We deny this new hand with respect and with love. BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from $excuses[(rand(0, count($excuses)-1))]. She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

And this is the new error message:

Parse error: syntax error, unexpected '(', expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/marainla/public_html/pageContent/q-genp.txt on line 438

Coothead?

Anyone?

A.

coothead
01-07-2021, 04:38 PM
...but I believe I'm making progress....


May I humbly suggest, that you don't hold your breath. :o


coothead

marain
01-07-2021, 05:12 PM
Coothead,

I'll try the resource you suggested.

A.

coothead
01-07-2021, 06:47 PM
Hi there marain,


before you go, the reason that I told you that your requirement was
impossible was because I knew that it was impossible in javascript.

Here is javascript example...


<script>
(function( d ) {
'use strict';

var number = 600,
item = 'apples';

d.querySelector('div').textContent =
'We have ' + number + ' green ' + item + ' for you';
}( document ));
</script>

coothead

marain
01-07-2021, 07:04 PM
Are you sure? What about

[CODE]const AGE = 25;
console.log(`I'm ${AGE} years old!`);[\CODE] ?

See https://www.w3docs.com/snippets/javascript/how-to-do-string-interpolation-in-javascript.html

A.

coothead
01-07-2021, 07:46 PM
Hi there marain,


the example you gave is a different kettle of fish.


it is using const rather than var
it is using backticks rather than quotes
the example that I gave used var and
quotes to match your PHP example



coothead

marain
01-07-2021, 07:53 PM
OK. Thanks for your patience.

A.

marain
01-07-2021, 09:23 PM
Solved! Here is the winning code:


echo "<br /><br />Your final quota of hands for this session was {$numbers[$_SESSION['limit']]}. This would have been hand number {$numbers[min(($_SESSION['bigCounter']+1),count($numbers)-1)]}. For that reason, we must deny at the moment your efforts for a new hand. We deny this new hand with respect and with love. BUT do not dispair: You can begin a <i>new</i> session when our webmistress returns from {$excuses[(rand(0, count($excuses)-1))]}. She should be coming back in a while. When she does, it will make her so happy if you are here. We hope you will not disappoint her. She will cheerfully review your starting quota of poker hands and, if necessary, adjust it.<br /><br />So hang out or, if necessary, come back later. Or feel free to refresh your <i>quotation</i>, above. You can do that while waiting!";

The problem arose from the fact that when I used the script interpolation method, it became necessary to put braces around ALL of the interpolated variables.

Coothead, I appreciate the attention to this problem that you provided.

BTW, the page on which this statement appears (in case anyone is interested) is https://www.marainlaw.com/page.php?here=quotations.

A.

coothead
01-07-2021, 10:03 PM
Solved! Here is the winning code:.


Very well done!!!

Thanks for proving me wrong.


coothead

marain
01-07-2021, 10:16 PM
Trust me: That will not happen very often ;-)