473,473 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

true && print()

Hi.

function printx($str) {
echo $str;
}

true && printx("foo");
true && print("bar");
Why do I see "foo", but not "bar"?

According to the manual, print and echo are language constructs, not
functions. That seems to be the reason why they don't behave as
expected, but what I'm looking for is an explanation. Is there a
rationale for not executing print() in this context?

tia,
stefan
Jul 17 '05 #1
3 1663
Stefan Weiss <sp******@foo.at> wrote:
Hi.

function printx($str) {
echo $str;
}

true && printx("foo");
true && print("bar");
Why do I see "foo", but not "bar"?

According to the manual, print and echo are language constructs, not
functions. That seems to be the reason why they don't behave as
expected, but what I'm looking for is an explanation. Is there a
rationale for not executing print() in this context?


You GAVE the explanation. What you have written there are expressions.
printx is a function which returns a value (implicitly), and can thus be
used in an expression. "print" is a statement; it does not return a value,
and thus cannot participate in expressions.

C has made us all lazy; people aren't aware of the difference between an
expression and a statement. Consider that you are asking to do the same
thing as this in C:

1 && while( x == 3 ) {
dowhat(x);
}
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #2
Tim Roberts wrote:

You GAVE the explanation. What you have written there are expressions.
printx is a function which returns a value (implicitly), and can thus be
used in an expression. "print" is a statement; it does not return a value,
and thus cannot participate in expressions.

C has made us all lazy; people aren't aware of the difference between an
expression and a statement. Consider that you are asking to do the same
thing as this in C:

1 && while( x == 3 ) {
dowhat(x);
}


Actually, that's the main difference between print and echo. Print CAN
be used in expressions while echo can't. Print does have a return value
, and behaves like a normal function, despite it not actually being one.
See the last paragraph in the manual, which links to this faq:
http://www.faqts.com/knowledge_base/...l/aid/1/fid/40

In response to the OP, the code works just fine for me. It prints out
"foobar".
Jul 17 '05 #3
On 2005-06-17 08:08, kicken wrote:
Actually, that's the main difference between print and echo. Print CAN
be used in expressions while echo can't. Print does have a return value
, and behaves like a normal function, despite it not actually being one.
See the last paragraph in the manual, which links to this faq:
http://www.faqts.com/knowledge_base/...l/aid/1/fid/40
Yes, I am aware of the difference between print and echo, that is why I
used print in my example.
In response to the OP, the code works just fine for me. It prints out
"foobar".


Very interesting. I have tried the same script on several web servers
now, with the following results:

[SuSE 9.2, Apache/2.0.50]
This is localhost, running PHP 4.3.8
foobar

[SuSE 9.2, Apache/2.0.50]
This is localhost, running PHP 5.0.4
foobar

[Debian Sarge, Apache/2.0.53]
This is www.foo.at, running PHP 5.0.4
foobar

[Debian Sarge, Apache/1.3.33]
This is akira.foomatic.at, running PHP 5.0.4
foo
Huh.

The only interesting difference that I can see is that the last server
is running Apache 1 instead of Apache 2.
cheers,
stefan
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jo | last post by:
you sure !
11
by: Arpan | last post by:
<% If(False) Then Response.Write("False") Else Response.Write("True") End If %> In the above code, the Else condition will be executed. Why?
1
by: Sori Schwimmer | last post by:
Hi, I am working on an application which involves interprocess communication. More to the point, processes should be able to notify other processes about certain situations, so the "notifyees"...
1
by: Weaver | last post by:
This works fine: Me.ForecastCurr.Form.Filter = "Year = " + Str(CurrYear) Me.ForecastCurr.Form.FilterOn = True And when I add this: TextCurrYearTotal = Me.ForecastCurr.Form....
2
by: Kristof Taveirne | last post by:
Hi, I'm developing an application on PDA using WindowsCE. In my application I have several tabs at the bottom of my screen. However, in one of the tabs I've placed 2 radiobutton, used to switch...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
40
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python...
16
by: koutoo | last post by:
I tried writing a true and false If statement and didn't get anything? I read some previous posts, but I must be missing something. I just tried something easy: a = if "c" in a == True:...
3
by: Nathan Sokalski | last post by:
I am adding an onmouseover attribute using the Attributes.Add() method, and the String I am using for the value contains the & character. However, when rendered the & is converted to the HTML...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.