FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » include capturing wrong value
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
include capturing wrong value [message #184658] Tue, 14 January 2014 16:56 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
$go=$_GET['a'];
if(empty($go)){$go=0;}

if ($go>=60 and $go<=69) { include
"http://mroldies.net/songs/19".$go.".html";}
if ($go>="A" and $go<="Z") <<<<<<
{ include"http://mroldies.net/songs/".$go.".html";}

if ($go==2){include "http://mroldies.net/radio/24hours.php";}
if ($go==1){include"http://mroldies.net/test/index2.php";}
if ($go==0){include "http://mroldies.net/home1.php";}

Using this code I now get a warning stating that the file can't be found.
"Zero" returns true for the marked line.
I can see where that would be the case using or.
But not AND!
Since "Zero" is less than "A" then the condition returns false.
Why do I not get the same warning from the first match test?
"zero" is less than 69 so that should return true.
Re: include capturing wrong value [message #184659 is a reply to message #184658] Tue, 14 January 2014 17:23 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:

> $go=$_GET['a'];
> if(empty($go)){$go=0;}
>
> if ($go>=60 and $go<=69) { include
> "http://mroldies.net/songs/19".$go.".html";}
> if ($go>="A" and $go<="Z") <<<<<<
> { include"http://mroldies.net/songs/".$go.".html";}
>
> if ($go==2){include "http://mroldies.net/radio/24hours.php";}
> if ($go==1){include"http://mroldies.net/test/index2.php";}
> if ($go==0){include "http://mroldies.net/home1.php";}
>
> Using this code I now get a warning stating that the file can't be
> found.
> "Zero" returns true for the marked line.
> I can see where that would be the case using or.
> But not AND!

This is your fucked up comprehension of comparison.

> Since "Zero" is less than "A" then the condition returns false.

You are making an incorrect assumption about the way a string variable is
compared to the number 0. You are not comparing the string "Zero" with
the strings "A" and "Z", you are comparing the number 0 with the strings
"A" and "Z". If you check the relevant php documentation, you will
understand that the behaviour here is exactly as it is documented to be.

> Why do I not get the same warning from the first match test?
> "zero" is less than 69 so that should return true.

You are not comparing the string "zero", you are comparing the number 0.
You are only considering part of the test you are discussing in your
above statements. You need to consider the whole test. The behaviour
appears on inspection to be correct.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: include capturing wrong value [message #184660 is a reply to message #184659] Tue, 14 January 2014 17:50 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:

> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>
>> $go=$_GET['a'];
>> if(empty($go)){$go=0;}
>>
>> if ($go>=60 and $go<=69) { include
>> "http://mroldies.net/songs/19".$go.".html";}
>> if ($go>="A" and $go<="Z") <<<<<<
>> { include"http://mroldies.net/songs/".$go.".html";}
>>
>> if ($go==2){include "http://mroldies.net/radio/24hours.php";}
>> if ($go==1){include"http://mroldies.net/test/index2.php";}
>> if ($go==0){include "http://mroldies.net/home1.php";}
>>
>> Using this code I now get a warning stating that the file can't be
>> found.
>> "Zero" returns true for the marked line.
>> I can see where that would be the case using or.
>> But not AND!
>
> This is your fucked up comprehension of comparison.
>
>> Since "Zero" is less than "A" then the condition returns false.
>
> You are making an incorrect assumption about the way a string variable is
> compared to the number 0. You are not comparing the string "Zero" with
> the strings "A" and "Z", you are comparing the number 0 with the strings
> "A" and "Z". If you check the relevant php documentation, you will
> understand that the behaviour here is exactly as it is documented to be.
>
>> Why do I not get the same warning from the first match test?
>> "zero" is less than 69 so that should return true.
>
> You are not comparing the string "zero", you are comparing the number 0.
> You are only considering part of the test you are discussing in your
> above statements. You need to consider the whole test. The behaviour
> appears on inspection to be correct.

Point noted and understood.
Still, "AND" is the key. not "OR".
Both must be true to return true.
Since 0 (zero as string) ls not greater than "A" the condition should
return false.
Re: include capturing wrong value [message #184663 is a reply to message #184660] Tue, 14 January 2014 18:07 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
richard wrote:

> On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:
>
>> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>>
>>> $go=$_GET['a'];
>>> if(empty($go)){$go=0;}
>>>
> Point noted and understood.
> Still, "AND" is the key. not "OR".
> Both must be true to return true.
> Since 0 (zero as string) ls not greater than "A" the condition should
> return false.

You do not compare '0', but rather 0, as a simple var_dump($go) would
show. This is because empty('0') === true.

--
Christoph M. Becker
Re: include capturing wrong value [message #184664 is a reply to message #184660] Tue, 14 January 2014 18:10 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 1/14/14 9:50 AM, richard wrote:
> On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:
>
>> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>>
>>> $go=$_GET['a'];
>>> if(empty($go)){$go=0;}
>>>
>>> if ($go>=60 and $go<=69) { include
>>> "http://mroldies.net/songs/19".$go.".html";}
>>> if ($go>="A" and $go<="Z") <<<<<<
>>> { include"http://mroldies.net/songs/".$go.".html";}
>>>
>>> if ($go==2){include "http://mroldies.net/radio/24hours.php";}
>>> if ($go==1){include"http://mroldies.net/test/index2.php";}
>>> if ($go==0){include "http://mroldies.net/home1.php";}
>>>
>>> Using this code I now get a warning stating that the file can't be
>>> found.
>>> "Zero" returns true for the marked line.
>>> I can see where that would be the case using or.
>>> But not AND!
>>
>> This is your fucked up comprehension of comparison.
>>
>>> Since "Zero" is less than "A" then the condition returns false.
>>
>> You are making an incorrect assumption about the way a string variable is
>> compared to the number 0. You are not comparing the string "Zero" with
>> the strings "A" and "Z", you are comparing the number 0 with the strings
>> "A" and "Z". If you check the relevant php documentation, you will
>> understand that the behaviour here is exactly as it is documented to be.
>>
>>> Why do I not get the same warning from the first match test?
>>> "zero" is less than 69 so that should return true.
>>
>> You are not comparing the string "zero", you are comparing the number 0.
>> You are only considering part of the test you are discussing in your
>> above statements. You need to consider the whole test. The behaviour
>> appears on inspection to be correct.
>
> Point noted and understood.
> Still, "AND" is the key. not "OR".
> Both must be true to return true.
> Since 0 (zero as string) ls not greater than "A" the condition should
> return false.
>

comparing a 0 to a string is always going to be true, regardless of
direction or string.

0<='A' is true
0>='Z' is true
0>='A' is true


However, what you *can* do is this:
if (is_string($go) && strlen($go)===1 && ctype_alpha($go))
{include"http://mroldies.net/songs/".$go.".html";}
Re: include capturing wrong value [message #184665 is a reply to message #184660] Tue, 14 January 2014 18:25 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 14 Jan 2014 12:50:18 -0500, richard wrote:

> On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:
>
>> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>>
>>> $go=$_GET['a'];
>>> if(empty($go)){$go=0;}
>>>
>>> if ($go>=60 and $go<=69) { include
>>> "http://mroldies.net/songs/19".$go.".html";}
>>> if ($go>="A" and $go<="Z") <<<<<<
>>> { include"http://mroldies.net/songs/".$go.".html";}
>>>
>>> if ($go==2){include "http://mroldies.net/radio/24hours.php";}
>>> if ($go==1){include"http://mroldies.net/test/index2.php";}
>>> if ($go==0){include "http://mroldies.net/home1.php";}
>>>
>>> Using this code I now get a warning stating that the file can't be
>>> found.
>>> "Zero" returns true for the marked line.
>>> I can see where that would be the case using or.
>>> But not AND!
>>
>> This is your fucked up comprehension of comparison.
>>
>>> Since "Zero" is less than "A" then the condition returns false.
>>
>> You are making an incorrect assumption about the way a string variable
>> is compared to the number 0. You are not comparing the string "Zero"
>> with the strings "A" and "Z", you are comparing the number 0 with the
>> strings "A" and "Z". If you check the relevant php documentation, you
>> will understand that the behaviour here is exactly as it is documented
>> to be.
>>
>>> Why do I not get the same warning from the first match test? "zero" is
>>> less than 69 so that should return true.
>>
>> You are not comparing the string "zero", you are comparing the number
>> 0. You are only considering part of the test you are discussing in your
>> above statements. You need to consider the whole test. The behaviour
>> appears on inspection to be correct.
>
> Point noted and understood.
> Still, "AND" is the key. not "OR".
> Both must be true to return true.
> Since 0 (zero as string) ls not greater than "A" the condition should
> return false.

Look again at this line:

if(empty($go)){$go=0;}

That doesn't assign zero as string, it assigns zero as number.

As I have already said, the result is according to the documentation for
the number vs string comparison that you are carrying out!

You clearly HAVE NOT understood what you have just claimed that you
understood!

Hint - both *ARE* true.

0 >= "A" evaluates to true
0 <= "Z" evaluates to true

hence

0 >= "A" and 0 <= "Z" evaluates to true

See: http://www.php.net/manual/en/types.comparisons.php

I'm sure you'll spectacularly fail to comprehend what the tables on that
page show, but they are nonetheless the appropriate reference.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: include capturing wrong value [message #184669 is a reply to message #184658] Tue, 14 January 2014 21:20 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
richard <noreply(at)example(dot)com> wrote in news:18dy94v4tv51n.1f3ltkhc8door$.dlg@
40tude.net:

>
> $go=$_GET['a'];
> if(empty($go)){$go=0;}
>
> if ($go>=60 and $go<=69) { include
> "http://mroldies.net/songs/19".$go.".html";}
> if ($go>="A" and $go<="Z") <<<<<<
> { include"http://mroldies.net/songs/".$go.".html";}
>
> if ($go==2){include "http://mroldies.net/radio/24hours.php";}
> if ($go==1){include"http://mroldies.net/test/index2.php";}
> if ($go==0){include "http://mroldies.net/home1.php";}
>
> Using this code I now get a warning stating that the file can't be found.
> "Zero" returns true for the marked line.

No, it does not.

"Zero" is *greater than* "Z", as you can easily determine by running this at the command
line:
<?php
if ("Zero" > "Z") echo 'yes';
?>

Neither does string zero "0".

*Numeric* zero 0 does, however.

> I can see where that would be the case using or.
> But not AND!
> Since "Zero" is less than "A"

No, it is not. "Zero" is *greater than* "A".

> then the condition returns false.

The reason the condition returns false is that "Zero" is also greater than "Z".

> Why do I not get the same warning from the first match test?
> "zero" is less than 69 so that should return true.

RTFM. This is all explained at php.net in the descriptions of how PHP does comparisons
between strings, and between strings and numerics.
Re: include capturing wrong value [message #184730 is a reply to message #184660] Thu, 23 January 2014 17:50 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
richard, 2014-01-14 18:50:

> On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:
>
>> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>>
>>> $go=$_GET['a'];
>>> if(empty($go)){$go=0;}
>>>
>>> if ($go>=60 and $go<=69) { include
>>> "http://mroldies.net/songs/19".$go.".html";}
>>> if ($go>="A" and $go<="Z") <<<<<<
[...]
>> You are not comparing the string "zero", you are comparing the number 0.
>> You are only considering part of the test you are discussing in your
>> above statements. You need to consider the whole test. The behaviour
>> appears on inspection to be correct.
>
> Point noted and understood.
> Still, "AND" is the key. not "OR".
> Both must be true to return true.
> Since 0 (zero as string) ls not greater than "A" the condition should
> return false.

But your comparison is not "greater than" - it is "greater or equal than":

if($go>="A" and $go<="Z")

if $go is 0 (and not "0"!) - then the condition perfectly matches - 0 is
greater or *equal* than 0 and also less or *equal* than 0.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: include capturing wrong value [message #184731 is a reply to message #184730] Thu, 23 January 2014 18:05 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Thu, 23 Jan 2014 18:50:17 +0100, Arno Welzel wrote:

> richard, 2014-01-14 18:50:
>
>> On Tue, 14 Jan 2014 17:23:25 +0000 (UTC), Denis McMahon wrote:
>>
>>> On Tue, 14 Jan 2014 11:56:16 -0500, richard wrote:
>>>
>>>> $go=$_GET['a'];
>>>> if(empty($go)){$go=0;}
>>>>
>>>> if ($go>=60 and $go<=69) { include
>>>> "http://mroldies.net/songs/19".$go.".html";}
>>>> if ($go>="A" and $go<="Z") <<<<<<
> [...]
>>> You are not comparing the string "zero", you are comparing the number
>>> 0.
>>> You are only considering part of the test you are discussing in your
>>> above statements. You need to consider the whole test. The behaviour
>>> appears on inspection to be correct.
>>
>> Point noted and understood.
>> Still, "AND" is the key. not "OR".
>> Both must be true to return true.
>> Since 0 (zero as string) ls not greater than "A" the condition should
>> return false.
>
> But your comparison is not "greater than" - it is "greater or equal
> than":
>
> if($go>="A" and $go<="Z")
>
> if $go is 0 (and not "0"!) - then the condition perfectly matches - 0 is
> greater or *equal* than 0 and also less or *equal* than 0.

Arno, remember that one of the rules of dealing with richard is that he
never has a more fucked up understanding of something than when he thinks
he understands it.

What he doesn't understand is that:

1) the numeric value 0 is falsey

2) the string value "any string" is falsey

3) the string value "any other string" is falsey

( 0 >= "any string" ) -> ( falsey == falsey ) -> true

( 0 <= "any other string" ) -> ( falsey == falsey ) -> true

and of course:

( true and true ) -> true

Which is why, when his $_GET['a'] has no data, and he then assigns the
value 0 to the variable $go, the test:

($go>="A" and $go<="Z")

is interpreted as:

( 0 >= "any string" and 0 <= "any other string" )

is interpreted as:

( false >= false and false <= false )

is interpreted as:

( false == false and false == false )

is interpreted as:

( true and true )

and is thus true.

And even now that I have written the whole damn sequence out, he'll still
fail to comprehend it and manage to make the same fuck up next week /
month / year / decade for as long as he continues trying to code his
website.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: include capturing wrong value [message #184732 is a reply to message #184731] Thu, 23 January 2014 21:56 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Thu, 23 Jan 2014 18:05:10 +0000 (UTC), Denis McMahon wrote:
> And even now that I have written the whole damn sequence out, he'll still
> fail to comprehend it and manage to make the same fuck up next week /
> month / year / decade for as long as he continues trying to code his
> website.

If you'd included one of the classic

if ($a = '4') {
echo "Why does this always happen to me?";
}

ones, I think you would have aced it.

--
"The last refuge of the insomniac is a sense of superiority to the
sleeping world."
--Leonard Cohen, The Favourite Game
Re: include capturing wrong value [message #184733 is a reply to message #184731] Sat, 25 January 2014 09:20 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Denis McMahon, 2014-01-23 19:05:

[...]
> Arno, remember that one of the rules of dealing with richard is that he
> never has a more fucked up understanding of something than when he thinks
> he understands it.

I know. But I don't want his, sorry, bullshit stay uncommented -
otherwise people my find this via Google and think any of is findings
are true, since no one commented it.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: <script>alert(1)</script>
Next Topic: I Need to search over 100 largeish text documents efficiently. What's the best approach?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 00:49:43 GMT 2024

Total time taken to generate the page: 0.02620 seconds