473,791 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ 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 1677
Stefan Weiss <sp******@foo.a t> 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

11
2458
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
1862
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" would be able to act in certain ways. As processes are distributed on several machines, in different physical locations, my thinking was:
1
1907
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. Me.ForecastCurr.Form.Filter = "Year = " + Str(CurrYear) Me.ForecastCurr.Form.FilterOn = True
2
4547
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 between between 2 panels on that same tab. (I don't use nested tabs, because I noticed they always show at the bottom, which is unlogic in my application). The first Panel is a custom Panel in where I override the paint method
2
5099
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, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
40
2731
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 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
16
4500
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: Print "Yes" When I run this, it runs, but nothing prints. What am I doing wrong?
3
3237
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 representation of &amp; which causes my JavaScript not to work. What can I do to prevent the Add() method from modifying my value? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.