• Tom Dibble (unregistered) in reply to Reed
    Reed:
    Alan:
    The funny thing is people do that sort of thing all the time in shell scripting:
    if test x$HAVE_AVCODEC = xfalse; then
    

    That's because shell scripting isn't evaluated like a real language. It just expands variables, then evaluates the command. So if $HAVE_AVCODEC is actually empty, then the command expands to

    if test x = xfalse; then
     ...
    

    instead of

    if test = false; then
     ...
    

    which is invalid syntax for 'test' and the script will abort.

    Way off topic, but I always just put quotes around the possibly-empty variable names and the tested value. like:
    if test '$VAR' = 'false'; then
    ...
    

    IMHO more readable than the "magic prefix" pattern.

  • (cs) in reply to xtremezone
    xtremezone:
    As far as strpos() goes in PHP, I think it would be a lot simpler to just return -1 when the substring is not found, and the starting index when it is.
    I don't agree. Then people probably would write things like
    if (strpos($haystack, $needle)) {
       ...
    }
    and the execution would enter the if block even if $needle isn't found in $haystack. That would surely be confusing.

    As is now, there is only one confusing case: when $haystack starts with $needle.

    The best way would be to add a function in_str() that returns either true och false. Checking containment is probably the most common usage of strpos().

  • Maciej (unregistered) in reply to md2perpe
    md2perpe:
    and the execution would enter the if block even if $needle isn't found in $haystack. That would surely be confusing.

    As is now, there is only one confusing case: when $haystack starts with $needle.

    The best way would be to add a function in_str() that returns either true och false. Checking containment is probably the most common usage of strpos().

    A failure in a common case that will be tested and identified quickly is superior to a failure in a rare case that will take forever to surface, in my opinion.

  • Fred (unregistered) in reply to Gary
    Gary:
    Many years ago I worked on a set of programs in COBOL that contained the following statement at seemingly random places in the code.

    compute xtdfa = xtdfa * 1.0.

    I coded similar statements once upon a time. There were two different reasons.

    (1) On one system, it was necessary to defeat a bug in the compiler's code optimizer. The optimizer attempted to move code forward and out of loops. Sometimes it moved a computation too far forward, so result had the wrong value when it was used. A statement of the form x = x * 1.0 stopped the movement of expressions using x.

    (2) The other reason was that, on one computer (CDC 3600), floating point 1 was not a multiplicative identity. That is, for some numbers, x * 1.0 != x. The reason was that this processor truncated before normalizing and, when multiplying by 1.0, this had the effect of forcing the low bit of the product to be zero.

    Why did this matter? It's been a long time and I don't recall the details, but I was doing something with complex numbers and needed to check whether the real or imaginary part was the same as the scalar value I started with. Because the scalar value was multiplied by (1.0,0) or (0,1.0), I didn't always get equality until I replaced the original value by val = val * 1.0.

  • John (unregistered) in reply to Gedoon

    -1 is a valid position in that if you pass it to substr it goes 1 character back from the end of the string (i.e., the character in position -1 in "Cabbage" is 'e'). However, strpos doesn't return negative values, but from a strictly semantic point of view, returning the index (an integer) or false (a boolean) makes more sense. Any competant PHP programmer (which, sadly, there are very few of) is well aware of problems that arise with the incorrect number of = signs. (I have seen an authentication module with the line "if ($username = 'wyang')"; needless to say it was a horribly written system as it checked if people were administrators by checking their username through a series of if statements), but PHP isn't that bad a language.

  • Richard (unregistered) in reply to ComaVN

    This is actually sane. strpos usually returns an integer; if this is 0, it means "found it; it's at the beginning". However, strpos can also return falss, meaning "not found". You have to distinguish the two cases.

  • (cs) in reply to Pap
    Pap:
    anon:
    Three WTFs:
    1. they use PHP. A language where array[''] == array[0] is not for serious work.
    php > $array = array('' => 'foo');
    php > var_dump($array[''] == $array[0]);
    bool(false)
    

    ????

    And in case he somehow thought that if you assigned to an empty-string key to an empty array (a WTF here: PHP might call them arrays, but I think real programmers call them hashes), that you could also use it with [0], that's also wrong:

    php > $array[''] = "paula";
    php > var_dump($array);
    array(1) {
      [""]=>
      string(5) "paula"
    }
    php > var_dump($array[0]);
    NULL

    He might have been going for this:

    php > $array[] = "wooden table";
    php > var_dump($array);
    array(1) {
      [0]=>
      string(12) "wooden table"
    }
    php > var_dump($array[0]);
    string(12) "wooden table"

    This only happens to an empty array though, and it is a nice way to allow array appending, as opposed to having to actually write out 1 + last index (which for PHP is != length - then again, anyone who mixes numeric indices and string indicies should be locked away, and then shot 47 times).

  • (cs) in reply to anon
    anon:
    2) a woman named Gabriel??
    what?
  • Xythar (unregistered)

    This is the best code snippet WTF I've seen yet. I had this great mental image of a giant, complicated machine that just has a cabbage sitting somewhere in the middle for no apparent reason, but if you ever take it out the whole thing stops working. Very Terry Pratchett-esque.

  • Kris (unregistered)

    Actually, from what i read there, "Cabbage" can be replaced with any string of at least 1 char, ir you could move the admin directory on the server to inside another folder so that "/admin" will not be at strpos 0, which evaluates to false.

    So, in short, the real wtf is that strpos is not supposed to return a boolean, so don't use it's return value as one.

  • Marek (unregistered) in reply to George Nacht

    Maybe she's French? "Gabrielle" is pronounced (minus the lovely french accent) in the same way as "Gabriel"...

    captcha: dubya (wtf?)

  • Tyler (unregistered) in reply to ComaVN
    ComaVN:
    A language where you need to use constructs like boolean_expression !== false in a conditional statement?

    Wow. Just. Wow.

    No, you dont need to, but you can.

    You see in php if("0" == 0) is true and if("0" === 0) is false

    So you can decide on your own, if you want to check the type or just the content. Of course you should know what you are doing and most PHP "developers" (read: Script kiddies) dont even know what the difference is. My last boss wrote something like if($int == "0") and didnt even get why i LOLed.

    In PHP everything is easy and that is why nobody gets what is really going on, they shoot their foot, and dont feel the pain.

    The "Programmer" of the original WTF would have said "Whats wrong with it? Its working!" and thats the problem with all the PHP guys out there.

    Tyler

    Captcha: atari, noooo i had a C64, atari suxx

  • fool (unregistered)

    Too bad it will fail once something in the system triggers the cabbage collector routine.

  • BillyBob (unregistered) in reply to Gedoon
    Gedoon:
    The legendary "The Real WTF" is that Gabriel didn't understand why cabbage was needed and why it was a wtf. It takes an idiot to write the code, and a moderate programmer to point out the wtf, but it should also be obvious just why it is a wtf. This just shows how poor understanding of loose typing and strict comparison php programmers have in general.

    It amazes me that a number of people are confused with strpos when it says right in the manual why strpos is returning zero and that it may also return false and how to use !== false. Then we have these people concating cabbages to strings and other dumbells thinking it's funny but they don't quite know why. Read The Freaking Manual, dimwits!!!

    This girl is getting a harder time than she deserves.

    We don't know if she's worked with PHP before and I know that I don't check the reference manual on every single library call when maintaining code. Afterall, this is an incredibly bizarre thing to do in almost any language.

    No wonder people want to hire developers which are in a country as far away from them as possible....

    So, to use a famous quote, the real wtf here is not silly PHP behaviour, it's not inserting random words into a string, it's yet another example of a developer using comments to tell us what is going on rather than why. Another WTF which could have been avoided with good comments.

    (Someone needs to test this software on Konqueror)

  • blabla (unregistered) in reply to Paul

    The "ADMIM" typo reminds me of a content management system... There was a component called "<something>-manager", but in code it was often spelled "<something>-manger". I guess the german developer was fond of this typo or something. Of course, it was eventually noticed, fixed and committed to SVN, which was trivial to do.

    Some of these mispelled lines were saving stuff to database with the wrongly spelled component name. Meaning that any old version of the CMS would use "manger", while newer versions use "manager". It took quite a while to figure out why some stuff broke during a routine update.

  • (cs) in reply to Gary
    Gary:
    Many years ago I worked on a set of programs in COBOL that contained the following statement at seemingly random places in the code.

    compute xtdfa = xtdfa * 1.0.

    several of them were preceeded by comments indicating that the line of code was essential. In those days everything was upper case so the comment didn't particularly stand out.

    This was my first programming job and was mystified by the statements. It was a decimal number on a decimal machine so roundoff wasn't the answer.

    I asked others working on the code and the universal response was "We don't know. We took it out once and the program stopped working".

    i don't remember what language i had to pull that crap in, but it was a way to tell the compiler that "HEY WE'RE USING FLOATING POINT NUMBERS NOW INSTEAD OF INTEGERS" as in you'd kick a compiler warning for this

    int i = 10 float d = 2.5

    d = i/d //error However, for some asinine reason i = i + 0.0 //i swear to god d = i/d // no longer an error.

    Or even better (and looks STUPID) d = (i + 0.0)/d

    heh. stupid hacks to get around non-strongly typed variables.

  • (cs) in reply to Gedoon
    Gedoon:
    The legendary "The Real WTF" is that Gabriel didn't understand why cabbage was needed and why it was a wtf. It takes an idiot to write the code, and a moderate programmer to point out the wtf, but it should also be obvious just why it is a wtf. This just shows how poor understanding of loose typing and strict comparison php programmers have in general.

    It amazes me that a number of people are confused with strpos when it says right in the manual why strpos is returning zero and that it may also return false and how to use !== false. Then we have these people concating cabbages to strings and other dumbells thinking it's funny but they don't quite know why. Read The Freaking Manual, dimwits!!!

    No. The real legendary "WTF" is that PHP can return either a numeric or a boolean value from a call to strpos(). That's just idiotic, and whoever designed it that way should find another line of work. RTFM doesn't matter - stupidity is stupidity, even if it's documented.

  • (cs) in reply to Gedoon
    Gedoon:
    The language itself is loose-typed and a programmer should know this when working with it. strpos is perfect for not one but two uses: it can detect the position of a string within a string, if you want to do something for the string in that position, on the other hand it can be used just to detect if the string is in the other string at all.

    So how does that make returning two different data types OK? It's still moronic.

    Gedoon:
    Tell me, what should the function return, when the function checks the place where a string begins, and the string is not found?

    Since it returns a numeric value if the string is found (0 based), a value less than zero would seem to be appropriate.

    Gedoon:
    The very nature of this function is ambiguous: it will always return two different kinds of answers:

    No. It's going to return one type of answer: the numeric index of the substring within the string. If the string is not there, it should return a numeric value to indicate that fact.

    The logic you're using is similar to TRUE, FALSE, FILE_NOT_FOUND logic for boolean values.

    Keep on posting, though. I like reading the real WTF s.

  • (cs) in reply to Island Usurper
    Island Usurper:
    For all of PHP's weirdness, strpos() really can't return -1 for "String not found." That's because -1 is a valid character position in a string, and false is not.

    However, anybody who writes a strpos function to return both positive and negative indexes should be shot.

    WTF? How can -1 be a valid character position in a string? If an index into the string is zero-based, how can string[-1] exist? And if string[-1] can somehow exist, can index -99? Even -99 would be a better return value than false.

    And people say VB is a badly designed language...

  • (cs) in reply to Gedoon
    Gedoon:
    I fail to see a difference. In one case you'll be comparing to -1, and in the other case comparing to "false". "At least it's not a boolean", wtf? What's wrong with explicitly comparing to a boolean?

    Oh, good! You kept posting! We get real WTF content today!

    Gedoon:
    Php will silently accept them and make the best of them, and in most cases this is fine when your comparing integer strings to integers. No need for cumbersome atoi's and such!

    WTF is an "integer string"?

    Gedoon:
    But every now and then you bump into strpos and such, and you actually need to do some typechecking before letting php guess how to compare them. That's where the type-specific comparison is needed. It's as simple as that. In php it's not a crime or a wtf to compare something to false. Some might call it a workaround, I see it as a language feature. The wtf is that php programmers in general are not aware of this...

    A "language feature"? It's simply stupidity in the design.

    You really are the one who designed TRUE, FALSE, FILE_NOT_FOUND, aren't you? Why didn't you 'fess up when it was posted? We all could have enjoyed the laugh then, instead of waiting until now.

    Gedoon:
    EvanED:
    Of course, if -1 is a valid return value... then there goes that option.
    Well it's not valid. Don't know what that fellow has been smoking who suggested it, but a string match can't start at a negative index. 0 is the lowest value it may return. If it could in fact be a negative index then what the hell would it mean? The string matches to the non-existing character before the first one?. That just makes no sense.

    It makes no sense, but it's as sensible as returning either an integer or a boolean from the same function.

    No matter how you argue it, this is poor design. While dynamic typing has it's uses, the way PHP uses it is extremely moronic. "Gee, this function can return the integer index if the substring exists, the boolean false if it doesn't, or "Gedoon" if the design is stupid." I get "Gedoon" back.

  • (cs) in reply to Pap
    Pap:
    if (strpos($mystring, $findme) != -1) { ...

    Which is no more or less complicated than:

    if (strpos($mystring, $findme) !== FALSE) { ...

    Who said anything about more complicated? This discussion is about what's logical. Returning two different data types from the same function call is idiotic.

    If the function returns an integer value (the index of a substring within a string if it exists), it should be consistent and return an integer value if the substring does not exist. That's logical, and avoids the need to spot the warning in the docs. (That's assuming that the designers of PHP were intelligent enough to write in the docs "WARNING! WARNING! WARNING! We made an extemely stupid design decision in this function, and you should read this section carefully! WARNING! WARNING! WARNING!" and repeated it several times in the strpos() section.

  • (cs) in reply to xtremezone
    xtremezone:

    We never said it was more 'complicated'. It is, in my opinion, not as logical.

    Finally! A sane voice!

    xtremezone:
    The point is that === and !== are 3\/!1.

    I much prefer to see ($something != -1) than ($something !== false).

    Besides, consider their meaning:

    ==     (is equal to)
    ===    (is exactly equal to)
    WTF    (=== and !==)

    I see it more like

    ==     (might be equal)
    ===    (now you can be sure)
    
  • (cs) in reply to md2perpe

    [quote user="md2perpe"] I don't agree. Then people probably would write things like

    if (strpos($haystack, $needle)) {
       ...
    }

    and the execution would enter the if block even if $needle isn't found in $haystack. That would surely be confusing. [/quote]

    Oh, good. Another one. :-)

    People should write things like

    if (strpos($haystack, $needle) != -1)
    

    or

    if (strpos($haystack, $needle) > -1)
    

    That is perfectly logical, and easy to read.

    I agree that another possible solution would be a separate function (like the in_str() you suggested). The current method, however, is really dumb. It's about as logical as calling Dell to place this order:

    PHP: "Hi, I'd like to order a 1 gig RAM chip. If you don't have that, please send two 512 meg chips. If you don't have those, send me a carpenter's hammer and a bag of potato chips." As is now, there is only one confusing case: when $haystack starts with $needle.

    The best way would be to add a function in_str() that returns either true och false. Checking containment is probably the most common usage of strpos().[/quote]

  • (cs) in reply to Richard
    Richard:
    This is actually sane. strpos usually returns an integer; if this is 0, it means "found it; it's at the beginning". However, strpos can also return falss, meaning "not found". You have to distinguish the two cases.

    Oh, goodie! Another of the TRUE, FALSE, FILE_NOT_FOUND camp joins us!

    I guess I was wrong earlier - looks like T/F/FNF was a team development effort instead of just an individual.

  • (cs) in reply to Kevi-chu
    Kevi-chu:
    But for at least this case, you need to take special consideration *anyway*. That is, the calling code needs to account for each of those two answers, and handle each case accordingly.

    That means that the answer "substring not found" needs to be distinguishable from a valid index.

    The only answer that matters is "substring not found" which in this case means "not an admin page". The only processing required is when the case is "this is an admin page" which is any index that is not false (or in a pretty world, -1).

    Therefore, if -1 was returned for "substring not found" there is no special consideration necessary. It's very simply:

    if(strpos($_SERVER['PHP_SELF'], "admin/") != -1)
    {
        // Stuff...
    }
    I consider === and !== to be special consideration. A single != conditional is not special consideration at all.
    Kevi-chu:
    The real WTF ;) is not with dynamic typing, but with the fact that PHP considers "", 0, NULL and FALSE all to be false boolean values. That means you have to use a type-strict comparison to distinguish an index of 0 from a boolean FALSE return value.
    I think NULL, false, and 0 should be considered false when evaluated as a boolean expression. All else should be considered true.
    Kevi-chu:
    I've found Ruby's approach much easier (having spent a lot of time in both languages): nil and false are considered false, while "", 0, 1, 5389, true, :foobar (a symbol), "bazquux", and anything else other than nil and false are considered true. Thus, the Ruby-equivalent calling code can do the if (strpos(foo, bar)) comparison with impunity, and The Right Thing(tm) will happen.

    http://us3.php.net/substr

    A negative index means the index from the end of the string. Thus if strpos() returned -1 on failure, it would muddy the semantics of the type "string index".

    In the manual for substr() the start parameter/argument can be supplied as a negative index, which would result in a returned substring beginning at the startth character from the end of the string.

    For example:

    $mystring = "I am a string.";
    
    println(substr($mystring, 5)); // Would return "a string."
    println(substr($mystring, -5)); // Would return "ring."
    "string index" isn't a type. The type is integer and it's used as an offset to index the characters.

    Returning -1 would not muddy the waters; negative indexes muddy the waters. Simply reading the manual page would keep everybody clear on circumstance.

    If it's useful to index from the end of a string that can be easily done explicitly:

    println(substr($mystring, strlen($string)-index)));
    //     WHICH EVALUATES TO
    println(substr($mystring, 14-5));
    //     WHICH EVALUATES TO
    println(substr($mystring, 9));

    Output:

    ring.

    Special indexing is not necessary. It's probably PHP's way of catering to NON-programmers. General users trying to program is a major WTF.

    Addendum (2007-03-09 10:20): println(substr($mystring, strlen($string)-index))); // SHOULD HAVE BEEN println(substr($mystring, strlen($string)-5)));

    Addendum (2007-03-09 12:49):

    Sorry about the mistakes. I really do prefer being able to edit my post...

    println(substr($mystring, strlen($string)-index))); // SHOULD HAVE BEEN println(substr($mystring, strlen($string)-5)));

    /**** SHOULD HAVE BEEN ****/

    println(substr($mystring, strlen($mystring)-index))); // SHOULD HAVE BEEN println(substr($mystring, strlen($mystring)-5)));

  • (cs) in reply to Tyler
    Tyler:
    ComaVN:
    A language where you need to use constructs like boolean_expression !== false in a conditional statement?

    Wow. Just. Wow.

    No, you dont need to, but you can.

    But you MUST in this case! How else can you distinguish between 0 and false, which are both returns and mean different things? The function design is forcing you to use either === false or !== false.

  • Joel (unregistered) in reply to George Nacht
    George Nacht:
    Maybe I am completely wrong here, and it´s also not important, but which nation consider ,,Gabriel,, a girl´s name?

    In the nation of Microsoft, where the Hungarian notation tells you the referenced object's type ("G" for "Girl") and the mnemonic part "Abriel" (sometimes shortened to "Abby").

  • [guest] (unregistered) in reply to George Nacht

    If you don't know any girls named Gabriel, you should get out more. they know how to PARTAY!

    captcha: tacos. Mmmm, tacos. Could go for a nice side of nachos.

  • (cs) in reply to Gedoon
    Gedoon:
    It takes an idiot to write the code, and a moderate programmer to point out the wtf ...

    Damn, you caught me! (Please don't tell my boss.)

  • (cs) in reply to xtremezone
    xtremezone:
    Nodren:
    its just a matter of having a coder who understands that having register globals turned on is a BAD thing.

    The 'coder' should be initializing their variables and using the superglobal arrays. If they do this then the "register globals" directive will have no effect on their scripts.

    In any case, this directive has apparently been removed from PHP 6.0.0.

    I think functions should have a defined return type even in dynamically-typed languages. If not explicitly by the language contruct than by the language designers and developers as a good programming practice.

    It's generally true that in order to process a function's return value you need to know what type of value it is. It would save the programmer a check if the designers of php, and other dynamically typed languages, would design the langauge in this way.

    No functions come to mind that need to return different types... Anybody have an example of this?

    (Bad form, but I don't have time to check through the remaining posts...)

    I don't have an example, or a counter-exammple, but for my sins I spent 15 years programming in C on VOS ... a wonderful OS. All system calls are basically PL/1 based. PL/1 seems to have no idea of a return value (I'm not sure about this; I only used the C interface).

    As a result, a VOS programmer is led to using ret-by-value parameters, rather than guessing at what the "function" might evaluate to (which is in any case a relic of ancient Fortran, pre-IV, where subroutines and functions were different things. Perfectly reasonable in those days, but still).

    I have to admit, when I read other peoples' code (always a good test of a language), this seemed to work quite well on a type-safe basis.

    Other than that, all I can say is that PHP is a complete heap of WTF*ery. Have these people not heard of MVC?

    And have you tried to build the goddamn thing from scratch?

    I have. There are not enough showers in the world.

    Pass the goggles. Make sure they work, this time.

  • mirabilos (unregistered) in reply to Alan
    Alan:
    The funny thing is people do that sort of thing all the time in shell scripting:
    if test x$HAVE_AVCODEC = xfalse; then
    

    Oh no, that's just for hysteric raisins. In today's code for mksh et al. we use:

    if [[ $HAVE_AVCODEC = false ]]; then
    

    PS: This captcha thing sucks with lynx; look at how http://undeadly.org/ does it. And the textbox is horrendly(sp?) small in Lynx, but ^Xe opens up an external editor, luckily.

  • mirabilos (unregistered) in reply to Tom Dibble
    Tom Dibble:
    Way off topic, but I always just put quotes around the possibly-empty variable names and the tested value. like:
    if test '$VAR' = 'false'; then
    ...
    

    oO no '$VAR' - ITYW "$VAR" instead.

    Tom Dibble:
    IMHO more readable than the "magic prefix" pattern.
    VAR=-e
    

    Try again. Point taken.

  • Joseph Newton (unregistered) in reply to Island Usurper
    Island Usurper:
    For all of PHP's weirdness, strpos() really can't return -1 for "String not found." That's because -1 is a valid character position in a string, and false is not.

    However, anybody who writes a strpos function to return both positive and negative indexes should be shot.

    Nope. You seem to be confusing the return value with the optional third parameter, the start position. In order to allow efficient searching when a string is expected near the end of a string, PHP allows setting the start position in terms of distance from the end by using a negative integer. That does not mean it allows negative return values. PHP strings are not C char pointers.

  • Abdullah Admim (unregistered) in reply to Paul
    Paul:
    if ( ( !isset($_SESSION["IS_ADMIM"] ) ) ||
    ($_SESSION["IS_ADMIM"] == 0 ) )
    IS_ADMIM. Nice.
    What's wrong with that?
  • (cs)

    I hate scripting languages. I didn't want to start a new forum thread for this so I thought I would post it here.

    I just came across this code in an ASP/VBScript application.

    (Note: that the HTML <input> element is in another script and the ASP/VBScript is in a server-side script; not that it matters)

    ...
    <input type=</span>"checkbox" name="chkMyCheckBox" ... value="1" />
    ...
    ...
    

    If gobjSmartUpload.Form("chkMyCheckBox") = 0 Then gintMyCheckBox = 0 Else gintMyCheckBox = 1 End If

    ... gobjCommand.CommandText = "INSERT INTO SomeTable(...," & _ "MyCheckBox, ...) VALUES(...," & _ gintMyCheckBox & ", ...);" gobjCommand.Execute ...

     
    
    I came across this code thinking "WTF..."

    Then a co-worker tested it and said that it worked so I started outputting to confirm why it worked. Google confirmed my assumptions.

    Oh yeah, scripting langauges are evil.

    Interestingly enough, I recently found out that in JavaScript a NaN doesn't equal itself. For example:

    var x = parseInt("");
    
    if(x == x)
        document.write("Equal!");
    else
        document.write("Not equal!");
    Output:

    Not equal!

    (Tried to highlight things and move things down on new lines so it was easier to read... I don't prefer these highlighting schemes, however, nor do I prefer these languages...)

    Addendum (2007-03-13 11:31): Inevitably, I messed up the highlighting a bit... It should still be readable... :(

  • Maks Verver (unregistered) in reply to xtremezone

    Actually, the NaN-inequality follows from the IEEE floating point specification, that requires any comparison involving a NaN operand to return false (so NaN == NaN and NaN != NaN are both false).

    All programming languages that support IEEE floating point arithmetic (and almost all do to some extend) exhibit the same behaviour; it's not limited to JavaScript.

  • (cs) in reply to Xythar
    Xythar:
    This is the best code snippet WTF I've seen yet. I had this great mental image of a giant, complicated machine that just has a cabbage sitting somewhere in the middle for no apparent reason, but if you ever take it out the whole thing stops working. Very Terry Pratchett-esque.
    Sounds more like Douglas Adams' Total Perspective Vortex to me. It extrapolated the whole of the Universe from a piece of fruitcake.
  • (cs) in reply to KenW
    KenW:
    Richard:
    This is actually sane. strpos usually returns an integer; if this is 0, it means "found it; it's at the beginning". However, strpos can also return falss, meaning "not found". You have to distinguish the two cases.

    Oh, goodie! Another of the TRUE, FALSE, FILE_NOT_FOUND camp joins us!

    I guess I was wrong earlier - looks like T/F/FNF was a team development effort instead of just an individual.

    Make an argument, or STFU, Troll.

  • (cs) in reply to Joseph Newton
    Joseph Newton:
    Island Usurper:
    For all of PHP's weirdness, strpos() really can't return -1 for "String not found." That's because -1 is a valid character position in a string, and false is not.

    However, anybody who writes a strpos function to return both positive and negative indexes should be shot.

    Nope. You seem to be confusing the return value with the optional third parameter, the start position. In order to allow efficient searching when a string is expected near the end of a string, PHP allows setting the start position in terms of distance from the end by using a negative integer. That does not mean it allows negative return values. PHP strings are not C char pointers.

    Some people already touched on this. And I'm *very* late to the party. But other string manipulation functions in PHP can be passed a negative index value, which indicates the position in the string from the end. Now, supposing strpos() could return -1, that would be a valid string index you could plug into substr(). And then there would be no good indication of when strpos() had NOT found the string. In addition, you would have to perform a costly check with strstr() prior to calling strpos() to get your desired index. Hence, strpos() returns FALSE when it cannot find a string, and, thankfully, the designers of PHP provided the identity operator to help us identify which was which.

    QED.

    So what if PHP allows people to shoot themselves in the foot? A lot of us out here DO know what we are doing, and we DO understand static typing, dynamic typing, etc. All the ad hominem attacks in the world won't change that. PHP provides for me and mine and I'm damn good at it, and I'm also thankful there are a lot of people out there that aren't, because I get the biggest kick out of the WTFs that involve PHP.

    QED.

  • (cs) in reply to Maks Verver
    Maks Verver:
    All programming languages that support IEEE floating point arithmetic (and almost all do to some extend) exhibit the same behaviour; it's not limited to JavaScript.
    ...*sniff* :(

    Well, that's depressing. So why do we even need NaN? Before attempting to convert to a number shouldn't a programmer check that the value is numeric? If the programmer tries the conversion on a value that can't be evaluated as a number the system should throw an exception. What would be wrong with that?

    Try
        dblDouble = Convert.ToDouble(strString)
    Catch ex As ConvertToNotNumberException ' Made up...
        Throw ex
    End Try
  • LaughingVergil (unregistered) in reply to wiregoat

    I'm sure that this is an obfuscated function name. The actual name was probably

    CheckAndVerifyTheCurrentUsersRightsOnTheCurrentPage

  • squarelover (unregistered) in reply to mathew
    mathew:
    Funnily enough, I recently implemented a non-WTFy auth system using cryptographic hashes. I had to choose a secret salt to insert in the data before signing to make it harder to crack. Maybe I should choose "Cabbage".

    Why do I see so many password crypt examples that use a static string for a salt. By definition, salt has to be random or changing, otherwise matching passwords would still appear the same.

    http://en.wikipedia.org/wiki/Salt_(cryptography)

  • cnallbird (unregistered) in reply to anon

    "A language where array[''] == array[0] is not for serious work."

    1. it's your responsibility to use a language in a serious way. crap in, crap out!

    2. you don't like implicit casting? don't use it then. instead, rely on the === operator and distinctive identifiers (certainly not "" as an array index).

    3. why comply if a tool is more powerful than suits your purposes? use it the way(s) you like, ignore the other ways.

  • cnallbird (unregistered) in reply to cnallbird

    sorry, the word is "complain", not comply. stupid english language! it's got far too many words!!

  • (cs)

    Hi there...

    I'm Gabriel... and of course it was a little misunderstanding or I typed in wrong... one should not refer to me as "she" but rather "he"... No offence taken... WTF makes some of my days happier...

    About the "Cabbage Based Authentication"...

    I laughed my ass those days, when I had to modify that app., so much that I gained some kg... any way it kept me going on and I delivered the modifications on time...

    I'm pretty sure that if I wasn't that amused by the authentication method... I would have never completed those modifications...

Leave a comment on “Cabbage Based Authentication”

Log In or post as a guest

Replying to comment #:

« Return to Article