[PHP] Please explain: index.php/index/index
I don't understand it. index.php should be a file and indeed it's a file, so what does /index/index after it mean? There's no index directory under directory where index.php resides. -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21578728.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain: index.php/index/index
leledumbo schrieb: I don't understand it. index.php should be a file and indeed it's a file, so what does /index/index after it mean? There's no index directory under directory where index.php resides. Hi Leledumbo, what are you talking about? I think you are confused on this: http://www.domain.com/index or this http://www.domain.com/index.php Yes this is a Front Controller situation (Pattern). Please show the Zend Framework or other Frameworks that implements this Pattern (maybe the Command Pattern too ). Regards Carlos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain: index.php/index/index
Carlos Medina-2 wrote: this is a Front Controller situation (Pattern) Could you explain more on that? I've never seen anything like this in any tutorial I've found on the net. I'm using kohana framework. So, if I have index.php/index/index where does it actually go? -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579231.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain: index.php/index/index
2009/1/21 leledumbo leledumbo_c...@yahoo.co.id Carlos Medina-2 wrote: this is a Front Controller situation (Pattern) Could you explain more on that? I've never seen anything like this in any tutorial I've found on the net. I'm using Kohana framework. So, if I have index.php/index/index where does it actually go? it goes to index.php , apache disregards what's after index.php Kohana the reads that string, and loads the appropriate Controller / method. You can hide the index.php from your users via apaches mod_rewrite. Refere to the Kohana or Codeigniter doccumentation -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579231.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Torok, Alpar Istvan
Re: [PHP] Please explain: index.php/index/index
Is this web server specific? I can't get it to run under Microsoft IIS, but it works flawlessly in Apache. -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579384.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain: index.php/index/index
Never used IIS, but under the circumstances, i think you got your answer. I remember that codeigniter support many ways of getting that string, i believe kohana does the same. You probably need to change some configuration options for IIS 2009/1/21 leledumbo leledumbo_c...@yahoo.co.id Is this web server specific? I can't get it to run under Microsoft IIS, but it works flawlessly in Apache. -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579384.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Torok, Alpar Istvan
Re: [PHP] Please explain: index.php/index/index
leledumbo wrote: Is this web server specific? I can't get it to run under Microsoft IIS, but it works flawlessly in Apache. IIS 6 and below dont have an option like mod_rewrite, apparently IIS 7 does, I haven't tried it yet. There are a number of 3rd party apps that can add this functionality to IIS 6, some are free and some paid for, Im currently using Isap/rewrite from helicontech which works for my needs ( zend framework). Clive -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain: index.php/index/index
-Original Message- From: clive [mailto:clive_li...@immigrationunit.com] Sent: Wednesday, January 21, 2009 3:36 AM To: leledumbo Cc: php-general@lists.php.net Subject: Re: [PHP] Please explain: index.php/index/index leledumbo wrote: Is this web server specific? I can't get it to run under Microsoft IIS, but it works flawlessly in Apache. IIS 6 and below dont have an option like mod_rewrite, apparently IIS 7 does, I haven't tried it yet. There are a number of 3rd party apps that can add this functionality to IIS 6, some are free and some paid for, Im currently using Isap/rewrite from helicontech which works for my needs ( zend framework). IIRF - Ionics ISAPI Rewrite Filter [1] is totally free... and it supports the use of Regular Expressions [2] in your rewrite rules. If you're going to use any sort of MVC-based URLs in IIS, this library is a must-have. 1. http://www.codeplex.com/IIRF 2. http://www.regular-expressions.info HTH, // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain: index.php/index/index
Boyd, Todd M. wrote: IIRF - Ionics ISAPI Rewrite Filter [1] is totally free... and it supports the use of Regular Expressions [2] in your rewrite rules. If you're going to use any sort of MVC-based URLs in IIS, this library is a must-have. Thanks for the link, I'll try it tonight. -- View this message in context: http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21598988.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] This fact ruins my understanding of php :( please explain!
Thnaks for an explanation. Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... This has been explained a few times. PHP does shallow copies, or copy-on-write which means that the data is not actually copied until you change it. That is: $a = 1234567890; $b = $a; internally we do not copy the data from $a to $b until you change $b. We you use references we have a bit more work to do as we need to decouple this and indicate that copy-on-write should not be taking place. Basically things are optimized for the most common case. -Rasmus On Tue, 8 Oct 2002, Markas wrote: I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function getmicrotime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: :( This fact ruins my understanding of php :( please explain!
Thanks for ur interest. Seairth Jacobs [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a couple thoughts... 1) In some other languages, passing an array by value only passes the first element value, not the whole array. This may be happening here, which would explay the fast execution times. I don't know this for sure, but it could easily be tested by seeing what's in $a inside the function f(). 2) Try returning the array by reference... function f($a){return $a;} for ($i=0; $i 100; $i++){$a = f($big);} --- Seairth Jacobs [EMAIL PROTECTED] Markas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function microtime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] This fact ruins my understanding of php :( please explain!
I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function getmicrotime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain?
[PHP] This fact ruins my understanding of php :( please explain!
I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function microtime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] :( This fact ruins my understanding of php :( please explain!
I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function microtime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] This fact ruins my understanding of php :( please explain!
This has been explained a few times. PHP does shallow copies, or copy-on-write which means that the data is not actually copied until you change it. That is: $a = 1234567890; $b = $a; internally we do not copy the data from $a to $b until you change $b. We you use references we have a bit more work to do as we need to decouple this and indicate that copy-on-write should not be taking place. Basically things are optimized for the most common case. -Rasmus On Tue, 8 Oct 2002, Markas wrote: I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function getmicrotime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: :( This fact ruins my understanding of php :( please explain!
I have a couple thoughts... 1) In some other languages, passing an array by value only passes the first element value, not the whole array. This may be happening here, which would explay the fast execution times. I don't know this for sure, but it could easily be tested by seeing what's in $a inside the function f(). 2) Try returning the array by reference... function f($a){return $a;} for ($i=0; $i 100; $i++){$a = f($big);} --- Seairth Jacobs [EMAIL PROTECTED] Markas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I tried some trivial expirements: /* here I define an array $big, which I guess would eat ~100kb of memory */ for($i=0; $i1; $i++) { $big[$i] = 1234567890; } /* this func only returns the value it gets as a param...*/ function f($a){return $a;} $start = microtime(); /* here all the job is done */ for ($i=0; $i 100; $i++){$a = f($big);} /* --- every iteration I just pass $big array to this func and it simply returns it*/ $end = microtime(); /* here I find out the time the job above takes to run, similar to the code from the help:*/ function microtime($time){ list($usec, $sec) = explode( ,$time); return ((float)$usec + (float)$sec); } $time_start = getmicrotime($start); $time_end = getmicrotime($end); $time = $time_end - $time_start; echo Did nothing in $time seconds; So the script above takes on my server ~0.00115 sec, so as far as I understand, it takes php to copy that $big array which is rather large, at least 100 times... So I decided to change the function f($a): function f($a){return $a;} changed to function f($a){return $a;}, as you can see, I only wanted to pass that $a param by reference, without copying it, so I thought I win in performance and the 100 iterations will work faster, as no copying of such a large array $big (which is this time going to be passed by refernce) will be involved,... BUT this case the job took ~3.75093 seconds, which is 3262 times SLOWER !!! I also found out, that while using refernces, the time of job's run strictly depends on the $big array dimension, and while NOT using references, the time doesn't depend on that, but I thought just on the contrary. I thought, that while using references, we dont copy the data and therefore do not depend on that data amount, but the example above shows just the opposite results... What's going on, if anybody gets interested, please explain? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Please explain...
Can someone explain why this works? $x = 0; if ($x == foo) { print yeah; } This prints 'yeah', but i can't figure out why... -- Jan Rademaker [EMAIL PROTECTED] http://www.ottobak.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain...
I would guess that the string foo evaluates to integer 0 in the comparison because $x is an integer, so that $x = 0 = true Use === (in PHP 4) to do type checking as well. Rudolf Visagie Principal Software Developer Digital Healthcare Solutions mailto:[EMAIL PROTECTED] Tel: 011 2655478 Cell: 082 895 1598 -Original Message- From: Jan Rademaker [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 12:31 PM To: [EMAIL PROTECTED] Subject: [PHP] Please explain... Can someone explain why this works? $x = 0; if ($x == foo) { print yeah; } This prints 'yeah', but i can't figure out why... -- Jan Rademaker [EMAIL PROTECTED] http://www.ottobak.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain...
Because you are telling the parser to compare a numeric variable against something called foo which (in your context) has to be numerical too. Since foo has not been given any value, the parser defaults it to 0. So foo = 0. So is true that foo=$x=0. Alex. - Original Message - From: Jan Rademaker [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, March 19, 2002 11:30 AM Subject: [PHP] Please explain... Can someone explain why this works? $x = 0; if ($x == foo) { print yeah; } This prints 'yeah', but i can't figure out why... -- Jan Rademaker [EMAIL PROTECTED] http://www.ottobak.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain...
»Rudolf Visagie« sagte am 2002-03-19 um 12:19:04 +0200 : I would guess that the string foo evaluates to integer 0 in the comparison Hmm, shouldn't a filled string (foo) evaluate to TRUE, ie. to 1? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: [EMAIL PROTECTED] iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 1 day 23 hours 44 minutes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain...
Yes, if you were comparing to a boolean, but in this case you are comparing to an integer. -Original Message- From: Alexander Skwar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 12:51 PM To: Rudolf Visagie Cc: Jan Rademaker; [EMAIL PROTECTED] Subject: Re: [PHP] Please explain... »Rudolf Visagie« sagte am 2002-03-19 um 12:19:04 +0200 : I would guess that the string foo evaluates to integer 0 in the comparison Hmm, shouldn't a filled string (foo) evaluate to TRUE, ie. to 1? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: [EMAIL PROTECTED] iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 1 day 23 hours 44 minutes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain...
For interest's sake the following code: $x = 0; if ($x == foo) { echo This is an integer comparison with foo being .$x.br; } $y = true; if ($y == foo) { echo This is a boolean comparison with foo being .$y.br; } prints: This is an integer comparison with foo being 0 This is a boolean comparison with foo being 1 Cheers -Original Message- From: Alexander Skwar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 12:51 PM To: Rudolf Visagie Cc: Jan Rademaker; [EMAIL PROTECTED] Subject: Re: [PHP] Please explain... »Rudolf Visagie« sagte am 2002-03-19 um 12:19:04 +0200 : I would guess that the string foo evaluates to integer 0 in the comparison Hmm, shouldn't a filled string (foo) evaluate to TRUE, ie. to 1? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: [EMAIL PROTECTED] iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 1 day 23 hours 44 minutes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain...
AFAIK the problem reported comes from that $x is on the left but foo is on the right. so you convert foo to int, and because there is not digit in foo it is 0. ?php $a=4some; $b=$a+2; var_dump($b); ? int(6) ?php $x=0; if ($x==foo) echo foobar; ? ?php $x=1; if (foo==$x) echo fubar; // same with === ? Output: foobar foo evaluates as 0 in the comparison. Andrey - Original Message - From: Rudolf Visagie [EMAIL PROTECTED] To: Alexander Skwar [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, March 19, 2002 1:01 PM Subject: RE: [PHP] Please explain... For interest's sake the following code: $x = 0; if ($x == foo) { echo This is an integer comparison with foo being .$x.br; } $y = true; if ($y == foo) { echo This is a boolean comparison with foo being .$y.br; } prints: This is an integer comparison with foo being 0 This is a boolean comparison with foo being 1 Cheers -Original Message- From: Alexander Skwar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 12:51 PM To: Rudolf Visagie Cc: Jan Rademaker; [EMAIL PROTECTED] Subject: Re: [PHP] Please explain... »Rudolf Visagie« sagte am 2002-03-19 um 12:19:04 +0200 : I would guess that the string foo evaluates to integer 0 in the comparison Hmm, shouldn't a filled string (foo) evaluate to TRUE, ie. to 1? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: [EMAIL PROTECTED] iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 1 day 23 hours 44 minutes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Please explain...
Agreed. I thought that the type of the variable on the left of the comparison had something to do with it, but then I ran this code: $x = 0; if (foo == $x) { echo This is an integer comparison with foo being .$x. and on the left of the comparisonbr; } $y = true; if (foo == $y) { echo This is a boolean comparison with foo being .$y. and on the left of the comparisonbr; } and the output is: This is an integer comparison with foo being 0 and on the left of the comparison This is a boolean comparison with foo being 1 and on the left of the comparison So all that I can think is that there is a type precedence in == comparisons with numbers and boolean variables taking precedence over strings. Any ideas? -Original Message- From: Andrey Hristov [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 1:37 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Please explain... AFAIK the problem reported comes from that $x is on the left but foo is on the right. so you convert foo to int, and because there is not digit in foo it is 0. ?php $a=4some; $b=$a+2; var_dump($b); ? int(6) ?php $x=0; if ($x==foo) echo foobar; ? ?php $x=1; if (foo==$x) echo fubar; // same with === ? Output: foobar foo evaluates as 0 in the comparison. Andrey - Original Message - From: Rudolf Visagie [EMAIL PROTECTED] To: Alexander Skwar [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, March 19, 2002 1:01 PM Subject: RE: [PHP] Please explain... For interest's sake the following code: $x = 0; if ($x == foo) { echo This is an integer comparison with foo being .$x.br; } $y = true; if ($y == foo) { echo This is a boolean comparison with foo being .$y.br; } prints: This is an integer comparison with foo being 0 This is a boolean comparison with foo being 1 Cheers -Original Message- From: Alexander Skwar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 19, 2002 12:51 PM To: Rudolf Visagie Cc: Jan Rademaker; [EMAIL PROTECTED] Subject: Re: [PHP] Please explain... »Rudolf Visagie« sagte am 2002-03-19 um 12:19:04 +0200 : I would guess that the string foo evaluates to integer 0 in the comparison Hmm, shouldn't a filled string (foo) evaluate to TRUE, ie. to 1? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: [EMAIL PROTECTED] iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 1 day 23 hours 44 minutes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please explain...
This is because of type conversion, see also manual chapter 'Type juggling'. foo converted to integer type is also zero, if you try 1foo for example, it will convert to one. if you want to check without type conversion use the === operator instead. bvr. Jan Rademaker wrote: Can someone explain why this works? $x = 0; if ($x == foo) { print yeah; } This prints 'yeah', but i can't figure out why... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php