Re: [PHP] Re: Switch statement Question

2009-02-02 Thread Frank Stanovcak

tedd tedd.sperl...@gmail.com wrote in message 
news:p06240801c5aa0ed7d...@[192.168.1.101]...
 At 4:16 PM +0100 1/30/09, Jochem Maas wrote:
tedd schreef:
  At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:
   

  yes...that is legal.  as long as the statment resolves to a boolean it
  will
  work.  It's not technically correct, but it does work.

  There you go again. What's technically correct?

hiya tedd,

you mean to ask not technically correct ... I plead
that it's his statement that is not technically correct.

1. php does a soft comparison ('==' rather than '===') so the
results of each case expression is auto-cast to a boolean
(in the case of switch'ing on TRUE), ergo there is no 'as long',
statements will always resolve to a boolean ... only they may not
do it in a way that is readily understood by everyone.

2. the php engine specifically allows for 'complex expression'
cases testing against a boolean switch value ... not best practice
according to some but very much technically correct according to
the php implementation.


 Good explanation -- I think the drum he's beating is that some of use the 
 switch without actually using the main expression within the control, such 
 as:

 switch($who_cares)
{
case $a = $b:
// do something
   break;
case $a  0:
 // do something else
   break;
case $a  0:
// do something elser
   break;
   }

 The control works.

 However to him, technically correct means:

 switch($a)
{
case 0:
// do something
   break;
case 1:
 // do something else
   break;
case 2:
// do something elser
   break;
   }

 That's what I think he's advocating.

 Cheers,

 tedd


 -- 
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

very true since this is the way it is taught in every book.  Php, however, 
allows for other uses that weren't technically in the original plan for 
this command from other languages.  The problem is I shave my head, so I 
have no hairs to split over this one.  :)

Frank 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Switch statement Question

2009-01-31 Thread tedd

At 4:16 PM +0100 1/30/09, Jochem Maas wrote:

tedd schreef:

 At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:

  

 yes...that is legal.  as long as the statment resolves to a boolean it
 will
 work.  It's not technically correct, but it does work.


 There you go again. What's technically correct?


hiya tedd,

you mean to ask not technically correct ... I plead
that it's his statement that is not technically correct.

1. php does a soft comparison ('==' rather than '===') so the
results of each case expression is auto-cast to a boolean
(in the case of switch'ing on TRUE), ergo there is no 'as long',
statements will always resolve to a boolean ... only they may not
do it in a way that is readily understood by everyone.

2. the php engine specifically allows for 'complex expression'
cases testing against a boolean switch value ... not best practice
according to some but very much technically correct according to
the php implementation.



Good explanation -- I think the drum he's beating is that some of use 
the switch without actually using the main expression within the 
control, such as:


switch($who_cares)
   {
   case $a = $b:
   // do something
  break;
   case $a  0:
// do something else
  break;
   case $a  0:
   // do something elser
  break;
  }

The control works.

However to him, technically correct means:

switch($a)
   {
   case 0:
   // do something
  break;
   case 1:
// do something else
  break;
   case 2:
   // do something elser
  break;
  }

That's what I think he's advocating.

Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Switch statement Question

2009-01-30 Thread tedd

At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:

 

yes...that is legal.  as long as the statment resolves to a boolean it will
work.  It's not technically correct, but it does work.


There you go again. What's technically correct?

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Switch statement Question

2009-01-30 Thread Jochem Maas
tedd schreef:
 At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:
  

 yes...that is legal.  as long as the statment resolves to a boolean it
 will
 work.  It's not technically correct, but it does work.
 
 There you go again. What's technically correct?

hiya tedd,

you mean to ask not technically correct ... I plead
that it's his statement that is not technically correct.

1. php does a soft comparison ('==' rather than '===') so the
results of each case expression is auto-cast to a boolean
(in the case of switch'ing on TRUE), ergo there is no 'as long',
statements will always resolve to a boolean ... only they may not
do it in a way that is readily understood by everyone.

2. the php engine specifically allows for 'complex expression'
cases testing against a boolean switch value ... not best practice
according to some but very much technically correct according to
the php implementation.


 Cheers,
 
 tedd
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Switch statement Question

2009-01-29 Thread Frank Stanovcak

Alice Wei aj...@alumni.iu.edu wrote in message 
news:snt101-w587cd616331fc59b84834af0...@phx.gbl...

Hi,

  I have a code snippet here as in the following:

//Switch statements between the four options
switch($string) {
case :
$string= NOT book.author='All';
break;
default:
$string= $string . AND NOT book.author='All';
break;
}
  This code does work, but I am wondering if it is possible in the switch 
 statement clauses for me to do something like case does not equal to a 
 certain author name if I don't want $string with that content to be 
 processed. or, do I always use default in this case?

Thanks in advance.

Alice
_
All-in-one security and maintenance for your PC. Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

You mean as in...

switch($string){
case :
code
break;

case $string == 'some value':
code
break;

case in_array($string, $somearray):
code
break;

default:
code
};

yes...that is legal.  as long as the statment resolves to a boolean it will 
work.  It's not technically correct, but it does work. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: If statement question

2006-06-26 Thread Adam Zey

Alex Major wrote:

Hi list.
Basically, I'm still learning new things about php and I was wondering if
things inside an if statement get 'looked at' by a script if the condition
is false.
For example, would this mysql query get executed if $number = 0 ?

If ($number == 1) {
mysql_query($blah)
}

I know that's not really valid php, but hope it gets my point across. I was
just wondering from an optimisation perspective, as I don't want sql
commands being executed when they don't need to be (unnecessary server
usage). 


Thanks in advance for your responses.
Alex.


Stuff inside an if statement will be compiled (So it has to be free of 
syntax errors and such), but it won't be executed unless the condition 
is true.


Regards, Adam Zey.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: If statement question...

2004-10-10 Thread M. Sokolewicz
Gh wrote:
I would like to know how I can code the the following conditional
check if the $_GET['api'] does not exist, or is either set and has
no length or is set and is not an integer.
I am drawing a blank on the if statement to use
if(!isset($_GET['api'] || strlen($_GET['api']) == 0 || 
!is_numeric($_GET['api'])) {
// do something
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: If statement question...

2004-10-10 Thread M. Sokolewicz
M. Sokolewicz wrote:
Gh wrote:
I would like to know how I can code the the following conditional
check if the $_GET['api'] does not exist, or is either set and has
no length or is set and is not an integer.
I am drawing a blank on the if statement to use
I meant to say the following (notice the added brace ;))
 if(!isset($_GET['api']) || strlen($_GET['api']) == 0 ||
 !is_numeric($_GET['api'])) {
 // do something
 }
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php