w3schools Logo
Monday 21 May 2012
W3schools.in Developer Network
HTML tutorials
CSS tutorials
php tutorials and scripts
MySql tutorials
Learn C Programming
Operating system

flaw-in-and-or-logical-operator-php
From w3schools.in

Today, When I was doing some programming stuffs and I found out that there is serious flaw in the “and” , “or” logical operator of PHP. I’m not talking about the symbol “||” and “&&” logical operator. I’m talking about the “and” and “or” logical operator (operator with words).

Example of the flaw of using “and” and “or” logical operator

Look at the following example and notice the output of this example,

$return_val = false or true;
var_dump($return_val);  //prints bool(false)

$return_val = true and false;
var_dump($return_val);  //prints bool(true)

As you can see in the first example, “bool(false)” is the output in the browser. I don’t need to tell you that “false or true” is always true and there is no doubt about this. But look at the output, what a freaking output by the “or” operator of PHP.

And now, just look at the second example, you’ll see “bool(true)” as a output to the browser. What a ridiculous result? How can “true and false” can be true, it must be “false” without any doubt.

But, you’ll not get such a kind of rediculous result with “||” and “&&” logical operator.


This page was last modified on 14 Sep 2011 at 17:04:28.
Gautam Kumar
EDP Manager
http://www.connectsin.com
Related Posts
» Useful functions to tighten the security in PHP
» CodeIgniter A recommendation for PHP Programmer
» PHP Framworks Why when and which
» Solving Floating point number precision lost problem in PHP
» Handling array of HTML Form Elements in JavaScript and PHP
» How to filter user submitted data easily in PHP
» Prevent form post request from another domain in PHP
» Flaw in and or logical operator php
» Default arguments functions php
» Submit Form without Refreshing Page with Jquery
» MySQL Performance Tips
» Free ajax chat applications in PHP
» Return More Than One Value From a Function in PHP
» PHP Optimization Tips
» PHP Error Handling
» Useful PHP Classes and Libraries
» Useful Tools For PHP Developers
» PHP Frameworks
» Web based HTML Editors
» 301 redirect in PHP and .htaccess
» Hiding PHP file extension
» Rredirect Browser HTTPS SSL PHP
» Tighten php security functions
» PHP Framworks