473,889 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if an multiple statements

another topic though related to the previous post.

How do IF behave in php?

Say,
if( $goahead && copy($somefile1 , $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?

I can make a complex if system, but eventuallt I can keep it simple
here...
Jan 7 '08 #1
6 1607
On Mon, 07 Jan 2008 17:24:29 +0100, jodleren <so*****@hot.ee wrote:
if( $goahead && copy($somefile1 , $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?
In PHP, failure of $goahead will mean copy() is not checked/executed in
this case.
I can make a complex if system, but eventuallt I can keep it simple
here...
Well, short from a programmers standpoint indeed. Being more verbose often
doesn't hurt though, and makes code somewhat more flexible/debuggable.
Depends on the actual need offcourse.
--
Rik Wasmus
Jan 7 '08 #2
..oO(jodleren)
>How do IF behave in php?

Say,
if( $goahead && copy($somefile1 , $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?
PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

$rs = mysql_query(... ) or die(...);

Micha
Jan 7 '08 #3

"Michael Fesser" <ne*****@gmx.de wrote in message
news:pm******** *************** *********@4ax.c om...
.oO(jodleren)
>>How do IF behave in php?

Say,
if( $goahead && copy($somefile1 , $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?

PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like
more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?

most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.

cheers.
Jan 7 '08 #4
..oO(Steve)
>"Michael Fesser" <ne*****@gmx.de wrote in message
news:pm******* *************** **********@4ax. com...
>PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?
Correct, and one common name for that technique is "lazy evaluation" (or
"delayed evaluation"): the result of an expression is only calculated if
and when it's really necessary.
>most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.
AFAIK "short-circuit" is more related to logical expressions, whereas
"lazy evaluation" is the more general name and applies to many other
things as well.

Micha
Jan 7 '08 #5

"Michael Fesser" <ne*****@gmx.de wrote in message
news:75******** *************** *********@4ax.c om...
.oO(Steve)
>>"Michael Fesser" <ne*****@gmx.de wrote in message
news:pm****** *************** ***********@4ax .com...
>>PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?

Correct, and one common name for that technique is "lazy evaluation" (or
"delayed evaluation"): the result of an expression is only calculated if
and when it's really necessary.
>>most languages do it this way. of those that i've used, vb was the only
one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added -
'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.

AFAIK "short-circuit" is more related to logical expressions, whereas
"lazy evaluation" is the more general name and applies to many other
things as well.
hmmm...i didn't know that. first i'd heard of lazy eval.
Jan 7 '08 #6
On Jan 7, 6:54*pm, "Steve" <no....@example .comwrote:
"Michael Fesser" <neti...@gmx.de wrote in message
PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like
most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.
Well I would think the same way, but as you wrote, once tried VB one
knows, that one has to be careful...
There are really a lot of languages and scripts out there, so better
safe than not.

As for debugging/reading of code - this can really minimise code, and
by that give a better overview. Some may think it is a bit harder to
read, but I rather have a few lines of code than 3 screens of it.

Thanks, all
Jan 8 '08 #7

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

Similar topics

0
1377
by: Tim Hastings | last post by:
Hello, I am using MyODBC from VB and I want to submit a batch of insert statements in one call from my App. This is more efficient than making multiple calls from code because of the communication overhead. If I send a batch multiple statements separated by ; or ; + newline I get syntax errors pointing at the start of the next statement.. If I fire each statement one at a time with the ; at the end there's no problem.
4
16764
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from customers; I can execute each statement individually but get the 'you have an error in
7
6180
by: Glenn Davy | last post by:
Hidely hodley everyone I'd like to run a series of of sql ddl statements against an msde2000 server. Normally I just deploy cmd file that impliments as osql statement, but I'd like to store the 'patch' in an mdb file and use say ado or even a passthrough statement to execute it. The problem I've got Is I access (?) seems to require me to execute one ddl at a time, otherwise the script breaks at the 'go' statement. While I _could_ do...
2
3139
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work individually, but not together, Access help is as much use as a chocolate fireguard in this case! any suggestions or explainations would be gratefully appreciated:
24
3661
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if (val2 == -1)
6
1835
by: G.Ashok | last post by:
Hi, Does anybody know how Multiple polymorphism can be done in VB.NET or DOT doesn't support it? Is there any third party extensions available like for Java to do this? Regards, ....Ashok ------------------------------------------------------------------------ "It is beautiful for an engineer to shape and design the same way
7
20341
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables, if they do not already exist. In terms of ASP/ADO, that would be fine in a SQL Server Sense by a simply ASP/Server-Side JavaScript as such: var cnTemp = Server.CreateObject("ADODB.Connection");
2
5108
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add a new Data Source to to my VB 2005 project, and point to this stored procedure, the data source wizard only sees the 'first' select statement. Is there a way to load multiple tables in a DataSet from a single stored procedure with multiple...
3
8628
by: Tim | last post by:
Hi Folks, I'm used to a UNLOAD command that allows me to dump to a named flat file the results of any SELECT statement. Hence one can build a single SQL file which contains multiple SQL statements each of which 'unloads' to its own unique file. unload to 'file1.txt' select * from ...... unload to 'file2.txt' select * from ...... and so on....
0
9962
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
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
11198
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
10889
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
5829
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
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
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3256
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.