• (cs) in reply to ammoQ

    This does offer a rather elegent way to ensure data passed is actually a boolean:

    make_sure_is_boolean($val) {
      return invert_boolean(invert_boolean($val));
    }

    at least one type of variable won't be the source of your SQL injection!

  • (cs) in reply to versatilia
    versatilia:
    You're all missing the point..How many of you get flustered when your other half asks "aren't you going out?"

    <font size="6">M</font>y other half?  Is that my mom?  Or do you mean "the other half" of our basement where the furnace is?

  • (cs) in reply to ammoQ
    ammoQ:
    bugsRus:
    Anonymous:
    Anonymous:

    But return !$val is so much less readable... :-)

    the real wtf is the ugly need for '$'!

     

    Maybe its a string variable from the Commodore PET days, circa 1978



    Wasn't the $ after the variable name on the PET?  Oh well, thanks for the flashback.


    String variables like A$ were common in all basic dialects of the home computer era, e.g. Commodore 64, Timex/Sinclair ZX81, Acorn BBC, TI 99/4A, MSX, CPC464 etc.

    The opposite  style, e.g. $A is a relict of the unix shell (can't say if it appeared even earlier) and it is definitely a WTF in languages like PHP and Perl, because the $ sign is meaningless there. In the unix shell, $foobar is a variable but foobar is a string (identically to "abc") but in PHP (I think also in Perl, correct if I am wrong), it has no such meaning.


    In Perl, a scalar variable (int/float/string) is preceeded with $, an array variable is preceeded by @, and a hash table variable is preceeded by %.  So it's possible to have a $apple, @apple, and %apple, all of which are separate variables.  And calls to functions are preceeded (sometimes) by & (I didn't get advanced enough in Perl to understand why functions I write need the & but library functions don't need it).

    The Perl creator (Larry something I think) said he picked $ and @ because they looked like S(calar) and A(rray).  But I think he picked the word scalar to start with S so he could continue the unix shell convention...

    In PHP I don't think it carries much significance, except maybe to distinguish variables from functions in case they have the same name (maybe?).
  • (cs) in reply to ammoQ
    ammoQ:
    No references to Terry Pratchett yet?

    "Five exclamation marks, the sure sign of an insane mind." etc.

    One of my customers seems to know only two different punctuation marks: tripple+ exklamation marks and tripple+ question marks. His emails read like this:

    Hello Mr. Kitzmueller !!!!

    I have a question to you!!! Can we change xxx in program yyy????

    etc.

    Always a funny read.


    Memo: What business are we in????? We are in the Damnation Business!!!!!
  • database guy (unregistered)

    creating that function was really lame!!!!!!11!!1

  • (cs) in reply to kipthegreat

    You damn kids ....


    In Perl, a scalar variable (int/float/string) is preceeded with $, an array variable is preceeded by @, and a hash table variable is preceeded by %.  So it's possible to have a $apple, @apple, and %apple, all of which are separate variables.  And calls to functions are preceeded (sometimes) by & (I didn't get advanced enough in Perl to understand why functions I write need the & but library functions don't need it).


    The &func is left over from previous verions of Perl.


    The Perl creator (Larry something I think) said he picked $ and @ because they looked like S(calar) and A(rray).  But I think he picked the word scalar to start with S so he could continue the unix shell convention...


    Wall! Larry Wall. You should know that name. Scalar is a fairly common word to describe a scalar value :)


    In PHP I don't think it carries much significance, except maybe to distinguish variables from functions in case they have the same name (maybe?).


    PHP is a hybrid of the unix shell, perl, and c, with some of the OO parts borrowed from java. PHP variables are always prefixed with '$'.

  • (cs) in reply to Dorfl

    Dorfl:
    ammoQ:
    No references to Terry Pratchett yet?

    "Five exclamation marks, the sure sign of an insane mind." etc.

    One of my customers seems to know only two different punctuation marks: tripple+ exklamation marks and tripple+ question marks. His emails read like this:

    Hello Mr. Kitzmueller !!!!

    I have a question to you!!! Can we change xxx in program yyy????

    etc.

    Always a funny read.


    Memo: What business are we in????? We are in the Damnation Business!!!!!

    Is it just me or are the earlier books way funnier than the more recent ones? Was re-reading the colour of magic and just couldn't stop laughing.

  • (cs) in reply to OneFactor

    There are good and not so good books all over the series.  I for one thought that the best books were Eric, Soul Music and Night Watch, though I've not read Going Postal

  • robymus (unregistered) in reply to Djinn

    The $ in PHP will get interesting when you look up the "variable variables" section in the documentation. See some examples:
    abc - means the constant defined by define('abc', something) or (of nothing defined by that name) the string 'abc'
    $abc - the variable named abc
    $$abc - the variable, whose name is in the variable named abc - like $abc = 'foo'; $$abc refers to $foo :)
    $$$abc - for really weirdos ;)

    And this one will only get tricky when you find that you can use it for function call also: $$abc() is actually working (if memory serves :), so $abc = 'foo'; $foo = 'myfunc'; $$abc(); // will invoke myfunc()

    This thing is weird as it is, using reference _by name_. But actually in this context $ has a meaning: something like "lookup-by-name".

  • (cs)

    Alex Papadimoulis:

    Thankfully, there's some sanity left. Some people are so fed up with this overuse that they refuse to use the exclamation point anywhere. For anything. Even when writing code. Sure, it may make their code a bit strange, but every little bit counts ...

    <FONT color=#006600>/**
     * @return  true | false
     * @param $val bool The bool to invert
     * @desc Returns the
    */</FONT>
    <FONT color=#000099>function</FONT> invert_bool($val){
      <FONT color=#000099>if</FONT>($val == <FONT color=#000099>true</FONT>)
        <FONT color=#000099>return false</FONT>;
      <FONT color=#000099>if</FONT>($val == <FONT color=#000099>false</FONT>)
        <FONT color=#000099>return true</FONT>;
    }

    All booleans are ( by nature ) just itchin' to be inverted.  This generous function mearly allows them a few more moments of glory in the process.  In the fast-paced world we live in, the developer simply reminds us to slow down and let the variables live a little.

  • Anonymous (unregistered) in reply to olddog
    olddog:

    Zero is a theoretical bone. There's always the other half.

    olddog, what does your sig means?

  • Anonymous (unregistered) in reply to Anonymous
    Anonymous:
    olddog:

    Zero is a theoretical bone. There's always the other half.

    olddog, what does your sig means?

    mean, I mean

  • (cs) in reply to Anonymous
    Anonymous:
    Anonymous:
    olddog:

    Zero is a theoretical bone. There's always the other half.

    olddog, what does your sig means?

    mean, I mean

    Just a quantum pun about the number line. Do you believe in zero, or do you believe there's always half of a half...of a half?

  • Anonymous (unregistered) in reply to olddog
    olddog:
    Anonymous:
    Anonymous:
    olddog:

    Zero is a theoretical bone. There's always the other half.

    olddog, what does your sig means?

    mean, I mean

    Just a quantum pun about the number line. Do you believe in zero, or do you believe there's always half of a half...of a half?

    I don't understand why the "bone" is in there, but thanks for the reply (the rest makes sense now)!

  • Random Human (unregistered) in reply to robymus
    Anonymous:

    The $ in PHP will get interesting when you look up the "variable variables" section in the documentation. See some examples:
    abc - means the constant defined by define('abc', something) or (of nothing defined by that name) the string 'abc'
    $abc - the variable named abc
    $$abc - the variable, whose name is in the variable named abc - like $abc = 'foo'; $$abc refers to $foo :)
    $$$abc - for really weirdos ;)

    And this one will only get tricky when you find that you can use it for function call also: $$abc() is actually working (if memory serves :), so $abc = 'foo'; $foo = 'myfunc'; $$abc(); // will invoke myfunc()

    This thing is weird as it is, using reference _by name_. But actually in this context $ has a meaning: something like "lookup-by-name".



    And, being someone that programs PHP, there are only 2 uses I've ever found for a variable variable that isn't a WTF:
    1. Emailable forms where you want the array key of the post (form item name) to be variable so that it gets inserted into an email in the right spot without always doing a lookup on the array (yeah, this seems redundant, I know...but inserting using an array with keys into a string takes nice annoying curly brackets). Obviously you have to make sure that you use constants, or all variables are defined after the array -> variable conversion is done, otherwise you get emails going to the wrong place.
    2. Creating proper validation functions based on a database describe result for dynamic forms designed to fill out an unknown database table (using the ${$fields[$i][validation]}() syntax, or some such). Obviouslly you will want to set these yourself based on the field type from the describe command to make sure nothing wierd gets executed.
  • (cs) in reply to Anonymous
    Anonymous:
    olddog:
    Anonymous:
    Anonymous:
    olddog:

    Zero is a theoretical bone. There's always the other half.

    olddog, what does your sig means?

    mean, I mean

    Just a quantum pun about the number line. Do you believe in zero, or do you believe there's always half of a half...of a half?

    I don't understand why the "bone" is in there, but thanks for the reply (the rest makes sense now)!

    The "bone" is a metaphor. The question is an conversation starter in a room of people smarter than me.

  • (cs) in reply to diaphanein
    Anonymous:
    While I won't knock the usefulness of this (think std::not1 in STL), but how this was done is asinine.


    This guy deserves to be quoted for emphasis.

    You're all harping on this as a huge WTF, but <i>the existance of an invert_bool function</i> isn't at ALL a WTF, at least in a language that supports function pointers. (It looks like PHP might not; I don't know it well enough to say for sure, but I don't get any useful hits from a simple Google search.)

    The implementation of invert_bool IS a WTF, and that makes me think that the above analysis isn't really applicable in this case, but primative functions such as that are quite helpful for some styles of programming.
  • (cs) in reply to EvanED

    Ahh got to love PHP programmers, my favourite if statement was:

    if ($value == !null) { }

  • oh no mr bill (unregistered) in reply to Random Human
    Anonymous:
    And the corresponding "return_bool" function would be:

    function return_bool($val) {
        return !invert_bool($val);
    }


    Then, invert_bool could be:

    function invert_bool($val) {

        return !return_bool($val);

    }

  • ChiefCrazyTalk (unregistered) in reply to bugsRus
    bugsRus:
    Anonymous:
    Anonymous:

    But return !$val is so much less readable... :-)

    the real wtf is the ugly need for '$'!

     

    Maybe its a string variable from the Commodore PET days, circa 1978



    Wasn't the $ after the variable name on the PET?  Oh well, thanks for the flashback.

    Yep, you got me. The PET was the first computer I ever programmed on (or used, for that matter). IIRC, the % sign indicated integers. I think there were some other characters that indicated data typing as well. It wasn't just PETs, lots of old versions of BASIC made use of that.

  • (cs) in reply to danish
    danish:
    Ahh got to love PHP programmers, my favourite if statement was:
    if ($value == !null) { }

    Ahh. the fun difference between boolean and null is that, when testing, null can be either anything or nothing, while boolean can only be anything or not ( the thing is implied ).

  • (cs) in reply to WTF Batman
    WTF Batman:

    You laugh, but a product I used to support had a boolean configuration variable that contained a double negative in its name. So, to turn this feature off, you'd set the variable to true. It was something like:

    DontNotDoSomethingSomething = 1



    I was having a problem with Microsoft Word.  It insisted on showing me the "Getting Started" task pane every time it started up.  My desktop support guy pointed out a KB article on exactly this topic.  The solution turned out to be using REGEDIT to, well, I'll let them explain it in their own words:

    5.Right-click the DoNotDismissFileNewTaskPane key, and then click Delete.
    6.Click OK to confirm that you want to delete the DoNotDismissFileNewTaskPane key.

    Yes, that's right, I had to delete a registry entry that was preventing me from making the stupid pane NOT show up.  WTF!?
  • Not WTF (unregistered)

    The WTF is 73 (and counting) responses to a piece of code that does exactly what it is meant to do. 

    I don't know what the language is.  

    I don't care.

    The programmer is returning the reverse of whatever has been presented.

    The code is understandable.

    It does what it's meant do do.  (oops, I said that before).

    It's probably part of a very large system that is making megabucks for the people running the software, with very happy customers.

    The bottom line, is, after all, the bottom line.


























  • Kevin (unregistered) in reply to Not WTF

    The $ in PHP can be a bit of a convenience, although i find the $this->_foo and self::$foo to be poorly-designed.  The problem is that it was originally a very simple set of scripts that continued to grow.  That said, it can still be a somewhat-decent language.

    Anyhow... Given its runtime-interpreted nature, the $ helps signify that what you are referring to is a variable.  Go back to that it's runtime-interpreted and you can get things like this:

    $obj = new $objClass();

    No, it's not ideal, and few will recommend things like that, but it is available, and some people like it.  I just hope i never have to maintain their scripts.

  • Pi (unregistered) in reply to ammoQ
    In the unix shell, $foobar is a variable but foobar is a string (identically to "abc") but in PHP (I think also in Perl, correct if I am wrong), it has no such meaning.

    ARGH.<p>

    The $ is extremely important in perl5, designating that you are asking for a scalar value (as opposed to an array slice, @, or a hash slice, %.) If you come across perl code that uses 'barewords', as non-sigiled (funny-character prefixed) variables are known, it is more than likely not written with use strict' oruse warnings' turned on, which lets you get away with such chicanery.

  • (cs) in reply to Pi

    I have a novel interpretation for today's WTF: given that this guy named his function "invert_bool" instead of "negate" or similar, I think he was ignorant of boolean logic. Maybe he thought he has made a great invention. Sounds crazy, but we've seen that kind of ignorance before.

  • (cs) in reply to OneFactor
    OneFactor:

    Dorfl:
    ammoQ:
    No references to Terry Pratchett yet?

    "Five exclamation marks, the sure sign of an insane mind." etc.



    Memo: What business are we in????? We are in the Damnation Business!!!!!

    Is it just me or are the earlier books way funnier than the more recent ones? Was re-reading the colour of magic and just couldn't stop laughing.



    I aggree, the earlier books were better.
  • (cs) in reply to Not WTF
    Anonymous:
    The WTF is 73 (and counting) responses to a piece of code that does exactly what it is meant to do. 


    And could have been replaced by a simple "NOT" operator. May not be the worst WTF ever, but unless someone is paid by lines of code that mentioned piece of code could have been avoided. Only inexperienced or sloppy developers write more _code_ than necessary.

    l.

  • erlando (unregistered) in reply to Not WTF
    Anonymous:
    The WTF is 73 (and counting) responses to a piece of code that does exactly what it is meant to do. 


    No.. The WTF today is what the f... is this guy doing coding if he doesn't know about the !-operator? That is really basic knowledge.

    Also the naming of the function hints at a lack of understanding of boolean algebra.
  • duh!!! (unregistered) in reply to Kooch
    Kooch:
    function invert_bool($val) {
        return $val ? false : true;
    }

    Not only is there an Exclamation Point in that! It is so tall that it has to bend over to fit under the top line...
  • (cs) in reply to ammoQ

    Can't speak for PHP but Perl follows the shell convention - foobar could be a literal string, subroutine, object etc depending on context.  $foobar is a variable and 'foobar' is always a literal string.

  • (cs) in reply to versatilia

    Erm... well that's what I get for replying to a post on the first page without realising there are 2 pages...

  • Rene Saarsoo (unregistered) in reply to versatilia

    Well... sure Perl got the $ from UNIX shell (I guess especially from the awk programming language), and PHP inherited it from Perl, but not as some kind of redundant piece, but as a feature.

    Everyone seems to forget, that the main point of having variables prefixed with $ is that you can place them inside strings:

    echo "My name is $first_name $last_name.";

  • (cs)

    Oh my god, tell me this is !true... [:D]

  • (cs) in reply to robymus
    Anonymous:

    The $ in PHP will get interesting when you look up the "variable variables" section in the documentation. See some examples:
    abc - means the constant defined by define('abc', something) or (of nothing defined by that name) the string 'abc'
    $abc - the variable named abc
    $$abc - the variable, whose name is in the variable named abc - like $abc = 'foo'; $$abc refers to $foo :)
    $$$abc - for really weirdos ;)

    And this one will only get tricky when you find that you can use it for function call also: $$abc() is actually working (if memory serves :), so $abc = 'foo'; $foo = 'myfunc'; $$abc(); // will invoke myfunc()

    This thing is weird as it is, using reference _by name_. But actually in this context $ has a meaning: something like "lookup-by-name".

    All you say is !false ( [:D] ) - and I abuse this happily in a bb-code parser I wrote in PHP some years back... [:P] The joy of function-pointers, pointer-pointers and pointer-pointer-pointers in a scripting language. You gotta love it [6]

  • (cs) in reply to Rene Saarsoo
    Anonymous:
    Well... sure Perl got the $ from UNIX shell (I guess especially from the awk programming language), and PHP inherited it from Perl, but not as some kind of redundant piece, but as a feature.

    Everyone seems to forget, that the main point of having variables prefixed with $ is that you can place them inside strings:

    echo "My name is $first_name $last_name.";



    PHP: We are talking about a language that follows the C convention of using == for comparison and = for assignment, because it saves a tiny bit of work, assuming that the later is more often used. This philosophy doesn't match at all with the $var style. Things like that make PHP in my eyes one of the ugliest languages ever defin^h^h^h^h^h^h grown.

  • davidbarrett (unregistered) in reply to mlathe
    mlathe:

    <FONT color=#006600><FONT face="Times New Roman" color=#000000>I like exclamation points.</FONT></FONT>
    <FONT color=#000099>function</FONT> invert_bool($val){
      <FONT color=#000099>if</FONT>($val != <FONT color=#000099>true</FONT>)
        <FONT color=#000099>return !false</FONT>;
      <FONT color=#000099>if</FONT>($val != <FONT color=#000099>false</FONT>)
        <FONT color=#000099>return !true</FONT>;
    }

     

    Ah hahahahahah

    Thats great - I may start implementing things like this myself...

  • StringCheesian (unregistered)
    function invert_bool($val){
      return ($val === 0);
    }
  • (cs) in reply to duh!!!

    Anonymous:
    Kooch:
    function invert_bool($val) {
        return $val ? false : true;
    }

    Not only is there an Exclamation Point in that! It is so tall that it has to bend over to fit under the top line...

     

    Very good!!![;)]

  • (cs) in reply to ammoQ
    ammoQ:
    I aggree, the earlier books were better.

    It there ANY author that isn't true for? Publishers make potential authors sweat out those first books until they can't get better. Once the author has about 6 books published, people know they can write good stuff, and buy anything with their name on it. So publishers start publishing rough drafts - after all rough drafts are easier, more fun, and take 1/3rd the time as a polished book. The latter is most important because as we all know time is money.

    I have several wonderful books that I've replaced more than once because I keep wearing my copy out (many of them went paperback when I was a kid so there is no chance I can buy the more durable hardcover anymore). After reading some great book I go to the bookstore and see another book by that author and buy it, thus perpetuating the scam on readers.

    I've tried buying first books by unknown authors, but many of them are not worth reading. Anyone with an idea of what readers can do about it?

  • Dan (unregistered) in reply to Cratig

    You've spelt 'Brillant' wrong mate.

    Cheers,

    Dan

  • (cs) in reply to ammoQ
    ammoQ:
    bugsRus:
    Anonymous:
    Anonymous:

    But return !$val is so much less readable... :-)

    the real wtf is the ugly need for '$'!

     

    Maybe its a string variable from the Commodore PET days, circa 1978



    Wasn't the $ after the variable name on the PET?  Oh well, thanks for the flashback.


    String variables like A$ were common in all basic dialects of the home computer era, e.g. Commodore 64, Timex/Sinclair ZX81, Acorn BBC, TI 99/4A, MSX, CPC464 etc.

    The opposite  style, e.g. $A is a relict of the unix shell (can't say if it appeared even earlier) and it is definitely a WTF in languages like PHP and Perl, because the $ sign is meaningless there. In the unix shell, $foobar is a variable but foobar is a string (identically to "abc") but in PHP (I think also in Perl, correct if I am wrong), it has no such meaning.


    The sigil ($) isn't meaningless in perl by any means. It denotes a scalar variable, as opposed to a list (@) or a hash (%).  When using a hash element or list slice, you'd also use the $ sigil, because the target is a scalar ( %myHash is an entire hash, but $myHash{$element} is a single entry in the hash, which is always a scalar, hence $).

    The sigils ($, @, and %) are how perl handles typecasting and type definition. Once you get used to it, it makes it lots easier to read. No, really. I'm serious.
  • (cs) in reply to lofwyr
    lofwyr:
    Anonymous:
    The WTF is 73 (and counting) responses to a piece of code that does exactly what it is meant to do. 


    And could have been replaced by a simple "NOT" operator. May not be the worst WTF ever, but unless someone is paid by lines of code that mentioned piece of code could have been avoided. Only inexperienced or sloppy developers write more _code_ than necessary.

    l.



    Not true. The minimum possible code is often unreadable. Better to have a couple of extra lines to improve readability. Experienced coders, as opposed to prima donnas, know this.
  • ChiefCrazyTalk (unregistered) in reply to Dan

    Anonymous:
    You've spelt 'Brillant' wrong mate.

    Cheers,

    Dan

     

    So did Paula.  That's the point of the joke.  (See previous WTF).

  • (cs) in reply to hank miller

    hank miller:
    ammoQ:
    I aggree, the earlier books were better.
    It there ANY author that isn't true for? Publishers make potential authors sweat out those first books until they can't get better. Once the author has about 6 books published, people know they can write good stuff, and buy anything with their name on it. So publishers start publishing rough drafts - after all rough drafts are easier, more fun, and take 1/3rd the time as a polished book. The latter is most important because as we all know time is money. I have several wonderful books that I've replaced more than once because I keep wearing my copy out (many of them went paperback when I was a kid so there is no chance I can buy the more durable hardcover anymore). After reading some great book I go to the bookstore and see another book by that author and buy it, thus perpetuating the scam on readers. I've tried buying first books by unknown authors, but many of them are not worth reading. Anyone with an idea of what readers can do about it?

    Someone suggested that the decline of Piers Anthony occurred after his editor (Judy Lynn Del Rey?) died and stopped sending crap back for rewrite. As for avoiding the scam, I've had a few ideas...

    1. After reading a good series (Belgariad, Adept, Amber), avoid a follow up series like the plague. Exception: the Twins was a great follow up to the Dragons
    2. After reading a good trilogy (HitchHiker's, Foundation, Robots) don't read the fourth book in the "trilogy". Exception: the summer dragons were a great add on to autumn, winter, and spring.
    3. Avoid Quadrillogies.
    4. Avoid Prequels (Foundation, the Phantom Menace, the SoulForge). Exception: the Magician's Nephew, Belgarath the Sorcerer
    5. Avoid Midquels (Polgara the Sorceress)
    6. Avoid Weis without Hickman (the SoulForge)

    To give Discworld credit, it went impressively far before diving. I think he even went beyond three good ones for the Rincewind, Witches, Death, City Watch streams. Haven't read any Tiffany Aching.

  • Whatever (unregistered) in reply to versatilia

    Yeah but how many of you don't get flustered?

  • The Doc (unregistered) in reply to DavidK
    Ah, the joys of PHP.

    You know if you had mentioned the lack of type checking, then he probably would end up with:

    <font>function</font> invert_bool($val){
    <font>if</font>($val == <font>true</font>)
    <font>return false</font>;
    <font>if</font>($val == <font>false</font>)
    <font>return true</font>;
    if($val == 0)
    return 1;
    if($val == 1)
    return 0;
    if(is_null($val))
    return "";
    if($val == "")
    return NULL;
    if($val == "FileNotFound")
    return "FileFound";
    }
    														Or something to that effect ;)<br><br>actually, that's useless.. true, 1, FileNotFound all evaluate as 'true'<br><br>you'd need === to also check the type for that code to do anything<br></span>
    
  • dasmb (unregistered) in reply to bugsRus
    Hey give the coder a break.  Maybe the 1 key on thier keyboard was broken!!!!!!!

    Reminds me of an old Stephen Wright joke:

    The other day, I see a friend of mine and he says 'I haven't heard from you in a while.' I said, 'I can't call everybody I want.  See, I bought an imperfect telephone, and it has no five.'  He says, 'Oh my god -- how long have you had it?'  I said, 'I don't know -- my calendar has no sevens.'

  • (cs) in reply to Rene Saarsoo
    Anonymous:
    Well... sure Perl got the $ from UNIX shell (I guess especially from the awk programming language), and PHP inherited it from Perl, but not as some kind of redundant piece, but as a feature.

    Everyone seems to forget, that the main point of having variables prefixed with $ is that you can place them inside strings:

    echo "My name is $first_name $last_name.";

    Uh, yeah, right, funny how Ruby manages string interpolation without prefixing the fucking variable names eh.

    What PHP has is not a feature, it's a damn retarded stupidity, because while it does have a meaning it perl it has none in PHP

  • (cs) in reply to kipthegreat
    kipthegreat:
    Anonymous:

    Ah, this is very good error handling. The function returns nothing when the caller accidentally passes a $val that is not a bool. That way it's easy to tell when you've passed it bad data. Clearly the exclamation point has none of that kind of power.

     



    If this is indeed PHP, then everything has a boolean value, so one of "== true" and "== false" will always return true.

    Now, if he had written the function like this, then a non-boolean would get passed through with nothing changed (again, assuming this is PHP):

    <font>function</font> invert_bool($val){
    <font>if</font>($val === <font>true</font>)
    <font>return false</font>;
    <font>if</font>($val === <font>false</font>)
    <font>return true</font>;
    }
    Of course, maybe that is the behavior he was trying to get.  You can tell from the javadoc-style comment that his primary language is Java, and he wasn't used to a weakly-typed language like PHP.  Maybe he was afraid that ! would return something weird for a non-boolean?  Hard to say, but I think he was probably a Java programmer who was learning a new language when he wrote this.


    Now WTF would that function return if the parameter wasn't boolean?  Nothing? File Not Found?  I'm thankful i'm in a land where such nonsense is a lot harder to pull off (C# & Java).

Leave a comment on “Avoiding The Dreaded Exclamation Point”

Log In or post as a guest

Replying to comment #:

« Return to Article