Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Sebastian Krebs
2013/1/4 tamouse mailing lists > Bit operators & and | are NOT and should NEVER be confused with > Logical operators && and ||: > > > /** > * Bit operators in PHP > */ > > $format = "Decimal: %2d Binary: %4b\n"; > > > $a = 4; > $b = 6; > > > echo "Variable \$a:\n"; > printf($format, $a, $a);

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Lucas
On 01/03/2013 11:43 AM, Andreas Perstinger wrote: & is the bitwise and operator. So is a single pipe. http://php.net/manual/en/language.operators.bitwise.php -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe,

Re: [PHP] date problem

2013-01-03 Thread Jim Lucas
On 01/03/2013 01:57 PM, Marc Fromm wrote: $jes = 01/03/2012; # php -r "echo 01/03/2012;" 0.00016567263088138 You might want to put quotes around that value so it is actually a string and does not get evaluated. -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP Gener

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Volmar Machado
Based on what I learned. I create this simple sample that can occurs in a real world application. This simulate a system that needs to send a mail when a flag ($mail) is true, the system need to check if the category is passed with the flag to know the type of mail to send. Here is the results. ";

Re: [PHP] date problem

2013-01-03 Thread Jim Giner
On 1/3/2013 5:22 PM, Marc Fromm wrote: Thanks Jonathan. I removed the date() syntax function and it works. From: Jonathan Sundquist [mailto:jsundqu...@gmail.com] Sent: Thursday, January 03, 2013 2:16 PM To: Marc Fromm Cc: Serge Fonville; php-general@lists.php.net Subject: Re: [PHP] date problem

RE: [PHP] date problem

2013-01-03 Thread Marc Fromm
Thanks Jonathan. I removed the date() syntax function and it works. From: Jonathan Sundquist [mailto:jsundqu...@gmail.com] Sent: Thursday, January 03, 2013 2:16 PM To: Marc Fromm Cc: Serge Fonville; php-general@lists.php.net Subject: Re: [PHP] date problem Marc, When you take a date and do a str

Re: [PHP] date problem

2013-01-03 Thread Jonathan Sundquist
Marc, When you take a date and do a strtotime you are converting it to an int which you can compare to each other much easier. So for your above example you would be best doing. define('WSOFFBEGIN','09/16/2012'); $jes = 01/03/2012; if ( strtotime($jes) < strtotime(WSOFFBEGIN) ) { $error

RE: [PHP] date problem

2013-01-03 Thread Marc Fromm
Thanks for the reply. Every example on comparing dates in PHP that I found uses the "strtotime" function which I am using. What other type can I use? When is this example below supposed to work? // your first date coming from a mysql database (date fields) $dateA = '2008-03-01 13:34'; // your

Re: [PHP] date problem

2013-01-03 Thread Ken Robinson
At 04:57 PM 1/3/2013, Marc Fromm wrote: I am comparing to dates. define('WSOFFBEGIN','09/16/2012'); $jes = 01/03/2012; if ( date("m/d/Y", strtotime($jes)) < date("m/d/Y", strtotime(WSOFFBEGIN)) ) { $error = " MUST begin after " . WSOFFBEGIN . "\n"; } I cannot figure out why the

Re: [PHP] date problem

2013-01-03 Thread Serge Fonville
Hi. date returns a string You should compare a different type for bigger/smaller than HTH Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PARTITION in SQL Server https://connect.microsoft.com/SQLServer/feedback/det

Re: [PHP] date problem

2013-01-03 Thread Jonathan Sundquist
1/3/2012 is in fact less then 9/16/2012. On Thu, Jan 3, 2013 at 3:57 PM, Marc Fromm wrote: > I am comparing to dates. > > define('WSOFFBEGIN','09/16/2012'); > $jes = 01/03/2012; > > if ( date("m/d/Y", strtotime($jes)) < date("m/d/Y", strtotime(WSOFFBEGIN)) > ) > { > $error = " M

[PHP] date problem

2013-01-03 Thread Marc Fromm
I am comparing to dates. define('WSOFFBEGIN','09/16/2012'); $jes = 01/03/2012; if ( date("m/d/Y", strtotime($jes)) < date("m/d/Y", strtotime(WSOFFBEGIN)) ) { $error = " MUST begin after " . WSOFFBEGIN . "\n"; } I cannot figure out why the $error is being assigned inside the if st

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Andreas Perstinger
Volmar Machado wrote: >When the one of the operators were 2, the cases with "<" >returns 2 otherwise returns 0 (Or 1 when any operator is 1). And if >the operators are 1 and 2, return 0 too. Its curious for me. & is the bitwise and operator. You have to look at the binary representati

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Volmar Machado
2013/1/3 Marc Guay : > I received the message below addressed only to me, but I believe the > group could benefit. It looks like the single pipe is a bitwise > operator so you will get an integer as a result (and probably other > weird things to discover when using it on non-numbers). > > http://p

Fwd: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
I received the message below addressed only to me, but I believe the group could benefit. It looks like the single pipe is a bitwise operator so you will get an integer as a result (and probably other weird things to discover when using it on non-numbers). http://php.net/manual/en/language.operat

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Lucas
On 01/03/2013 09:25 AM, Marc Guay wrote: Hi Tedd, A little searching enlightened me to the fact that in other languages, a single | or& operator will cancel the short-circuiting so all of the evaluations are done before proceeding. However, they don't seem to exist in PHP so in your example it

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Tedd Sperling
On Jan 3, 2013, at 12:09 PM, David OBrien wrote: > From what I understood about || is once it sees a true the whole statement > is regarded as true so nothing else following matters so PHP ignores > everything in the conditional after it evaluates as true... > and once it sees a false the whole st

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
Hi Tedd, A little searching enlightened me to the fact that in other languages, a single | or & operator will cancel the short-circuiting so all of the evaluations are done before proceeding. However, they don't seem to exist in PHP so in your example it behaves the same as ||...? http://php.net

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Tedd Sperling
On Jan 3, 2013, at 11:49 AM, Marc Guay wrote: > I just ran this: > > if (($a = "foo") || ($b = "bar")){ >echo $a."".$b; > } > > and it only spat out "foo" so I'm guessing things have changed. :) > > Marc Marc et al: I joined late into this conversation, so I may be missing the point, bu

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread David OBrien
On Thu, Jan 3, 2013 at 11:49 AM, Marc Guay wrote: > Hi John, > > I just ran this: > > if (($a = "foo") || ($b = "bar")){ > echo $a."".$b; > } > > and it only spat out "foo" so I'm guessing things have changed. :) > > Marc > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscri

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread John Iliffe
On Thursday 03 January 2013 11:33:22 Marc Guay wrote: > > First, did the original poster realize that he was assigning a value > > to the variable $a in the 'if' statement? > > Hello, > > Yes, I did, and if you read my responses you can see that I came to > the realisations you describe. I don't

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
> First, did the original poster realize that he was assigning a value to the > variable $a in the 'if' statement? Hello, Yes, I did, and if you read my responses you can see that I came to the realisations you describe. I don't think that anyone suggested there was a bug. > $a is true (ie it

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread John Iliffe
On Thursday 03 January 2013 10:26:39 Jim Giner wrote: > On 1/2/2013 2:02 PM, Marc Guay wrote: > > Something else that's happening with this, which makes it a Bad Idea > > (tm) is that when the operator is "or", as it is in my real life > > scenerio, the 2nd variable occasionally doesn't get populat

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Geoff Shang
On Thu, 3 Jan 2013, Jim Giner wrote: The only time I use a single '=' symbol in an if statement is when I forget to use two of them! Must be my old school, old languages habits but this style of programming reminds me of the days when we used to pack empty spaces in assembler code with consta

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Giner
On 1/2/2013 2:02 PM, Marc Guay wrote: Something else that's happening with this, which makes it a Bad Idea (tm) is that when the operator is "or", as it is in my real life scenerio, the 2nd variable occasionally doesn't get populated if the first one returns true. if ($a = "foo" || $b = "bar"){