By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,492 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,492 IT Pros & Developers. It's quick & easy.

Very Weird Behavior

P: n/a
I started with the following code in an included file:

$CompanyBlock =
"$Company (Booth#: $Booth)\n".
"$Address\n".
"$City, $State $PostalCode\n".
"$Website\n".
"$Contact1, $Title1\n".
"Tel: $Phone\n".
"Fax: $Fax\n".
"Email: $Email1\n".
"Products/Services: $ProductService\n".
"Objectives: ";

I wanted to make some of the items conditional, but in so doing, I forgot
to change some of the . to ; and ended up with:

$CompanyBlock = $Company;
if ($Booth) $CompanyBlock.= " (Booth#: $Booth)";

$CompanyBlock.=
"\n".
"$Address\n".
"$City, $State $PostalCode\n";

if ($Website) $CompanyBlock.= "$Website\n";
if ($Contact1) $CompanyBlock.= "$Contact1";
if ($Title1) $CompanyBlock.= ", $Title1"; $CompanyBlock.= "\n";
if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
if ($Email1) $CompanyBlock.= "Email: $Email1\n".
if ($ProductService)
$CompanyBlock.= "Products/Services: $ProductService\n".

$CompanyBlock.= "Objectives: ";

The result? The file returns with no execution, not even of code before
the problem, and with no error message, not so much as a notice. It took
me a good while to narrow it down and spot the problem (there's quite a
bit of code before this in the file). I knew the file was being called,
but even an echo statement at the very beginning produced no output. The
execution of the main script was not affected.

I thought this might save someone else a bit of time if they happen to
have the same problem.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Nov 6 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Alan Little wrote:
I started with the following code in an included file:

$CompanyBlock =
"$Company (Booth#: $Booth)\n".
"$Address\n".
"$City, $State $PostalCode\n".
"$Website\n".
"$Contact1, $Title1\n".
"Tel: $Phone\n".
"Fax: $Fax\n".
"Email: $Email1\n".
"Products/Services: $ProductService\n".
"Objectives: ";

I wanted to make some of the items conditional, but in so doing, I forgot
to change some of the . to ; and ended up with:

$CompanyBlock = $Company;
if ($Booth) $CompanyBlock.= " (Booth#: $Booth)";

$CompanyBlock.=
"\n".
"$Address\n".
"$City, $State $PostalCode\n";

if ($Website) $CompanyBlock.= "$Website\n";
if ($Contact1) $CompanyBlock.= "$Contact1";
if ($Title1) $CompanyBlock.= ", $Title1"; $CompanyBlock.= "\n";
if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
if ($Email1) $CompanyBlock.= "Email: $Email1\n".
if ($ProductService)
$CompanyBlock.= "Products/Services: $ProductService\n".

$CompanyBlock.= "Objectives: ";

The result? The file returns with no execution, not even of code before
the problem, and with no error message, not so much as a notice. It took
me a good while to narrow it down and spot the problem (there's quite a
bit of code before this in the file). I knew the file was being called,
but even an echo statement at the very beginning produced no output. The
execution of the main script was not affected.

I thought this might save someone else a bit of time if they happen to
have the same problem.

Sorry, I think you code in a weird way..
What do you expect from if($varname) ?
Does your script rely on registerglobals = on?

Of course I cannot see the rest of your setup, so maybe I am talking bull.
;-)

Regards,
Erwin Moller
Nov 7 '05 #2

P: n/a
Carved in mystic runes upon the very living rock, the last words of
Erwin Moller of comp.lang.php make plain:
The result? The file returns with no execution, not even of code
before the problem, and with no error message, not so much as a
notice. It took me a good while to narrow it down and spot the
problem (there's quite a bit of code before this in the file). I knew
the file was being called, but even an echo statement at the very
beginning produced no output. The execution of the main script was
not affected.

I thought this might save someone else a bit of time if they happen
to have the same problem.
Sorry, I think you code in a weird way..


Perhaps, but it has no bearing on the issue. That is, if I used isset()
instead, perhaps it wouldn't tickle this particular bug, but it is in
fact a bug. Which reminds me, I should report it.
What do you expect from if($varname) ?


I expect PHP to tell me if it has a problem. While if ($var) may not be
ideal coding practice, it is legal.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Nov 26 '05 #3

P: n/a
If you checked the php error log it would have printed out something
like:

[27-Nov-2005 16:04:12] PHP Parse error: syntax error, unexpected T_IF
in etc......

i.e.

if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
if ($Email1) $CompanyBlock.= "Email: $Email1\n".

Take this section of code, your concatenating IF statements like
strings so of course it's not going to work.

You should start by going to http://www.php.net/manual/en/

Nov 27 '05 #4

P: n/a

Alan Little wrote:

Perhaps, but it has no bearing on the issue. That is, if I used isset()
instead, perhaps it wouldn't tickle this particular bug, but it is in
fact a bug. Which reminds me, I should report it.
It's not a bug, it's illegal code. You can't terminate a line with a
dot, and you can't concatenate an if statement into a string. It
produces a parse error and stops execution. If you don't get an error
message it is because of your settings. It is still an error, though.
What do you expect from if($varname) ?


I expect PHP to tell me if it has a problem. While if ($var) may not be
ideal coding practice, it is legal.


Legal, yes. Useful in this situation, no. What you are saying in effect
is "if the website name can be converted to a non-zero number, then..."

I don't mean to give offence, but you should consider coding like other
people do, at least until you understand the consequences of not doing
so.

Ian

Nov 28 '05 #5

P: n/a
Carved in mystic runes upon the very living rock, the last words of Ian
B of comp.lang.php make plain:
Alan Little wrote:

Perhaps, but it has no bearing on the issue. That is, if I used
isset() instead, perhaps it wouldn't tickle this particular bug, but
it is in fact a bug. Which reminds me, I should report it.
It's not a bug, it's illegal code. You can't terminate a line with a
dot,


Sure you can, unless you mean you can't terminate a statement with a
dot. Nothing wrong with terminating a line with a dot, if your intention
to to concatenate whatever's on the next line.
and you can't concatenate an if statement into a string.
Of course. As mentioned originally, I inserted the if's, and forgot the
change the appropriate dots to semicolons.
It produces a parse error and stops execution.
It does neither. No error, and execution resumes in the main code (this
was in an included file).
If you don't get an error message it is because of your settings.
error_reporting = E_ALL
> What do you expect from if($varname) ?


I expect PHP to tell me if it has a problem. While if ($var) may not
be ideal coding practice, it is legal.


Legal, yes. Useful in this situation, no. What you are saying in
effect is "if the website name can be converted to a non-zero number,
then..."


I understand. And it is useful in this situation. It basically is a
shortcut of if(strlen(trim($Website)))
I don't mean to give offence,
None taken.
you should consider coding like other people do, at least until
you understand the consequences of not doing so.


Well, I do understand exactly what the code is doing, but to be honest I
don't believe I've heard all the arguments against using it; I just know
there are some.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Nov 28 '05 #6

P: n/a
Carved in mystic runes upon the very living rock, the last words of Sean
of comp.lang.php make plain:
If you checked the php error log it would have printed out something
like:

[27-Nov-2005 16:04:12] PHP Parse error: syntax error, unexpected T_IF
in etc......
Assuming error logging is on, which it isn't in this case, but error
reporting is, and there was no error.
if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
if ($Email1) $CompanyBlock.= "Email: $Email1\n".

Take this section of code, your concatenating IF statements like
strings so of course it's not going to work.
I understand that. As stated in my original post, the code was initially
a single block of concatenation; I added the if's, and forgot to change
the appropriate dots to semicolons.
You should start by going to http://www.php.net/manual/en/


Gosh, a whole new world of enlightenment I hadn't seen before!

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Nov 28 '05 #7

P: n/a
Its display_errors in the php.ini which needs to be turned on that
displays errors as part of the output.

Nov 28 '05 #8

P: n/a
Carved in mystic runes upon the very living rock, the last words of Sean of
comp.lang.php make plain:
Its display_errors in the php.ini which needs to be turned on that
displays errors as part of the output.


Ah yes, that's turned off. It's still odd that it would continue execution
of the main code though, with a parse error in the included file. Even with
display_errors off, that is not the normal behavior.

Oh well.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Nov 28 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.