Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts

    Non Operator use of the Word AND???

    Hi,

    I was reading the Curl helper class from CodeIgnitor and it has a syntax I haven't seen before. It uses the word AND without an if statement. Can someone please tell me what it means and its purpose.

    PHP Code:
    $url AND $this->create($url); 
    Here is the entire construct function in the class.
    PHP Code:
        function __construct($url '')
        {
            
    $this->_ci = & get_instance();
            
    log_message('debug''cURL Class Initialized');

            if ( ! 
    $this->is_enabled())
            {
                
    log_message('error''cURL Class - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.');
            }

            
    $url AND $this->create($url);
        } 

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    it's a logical operator,
    PHP Code:
    $url AND $this->create($url); -- if both are true then will return true
    http://www.w3schools.com/php/php_operators.asp

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    ^
    The actual purpose here is to bypass an if check to call $this->create(). Its the same as doing:
    PHP Code:
    if (!empty($url))
    {
        
    $this->create($url);

    Since its logical, AND will never proceed beyond the first false result. Empty is considered false, so its safe to do so. I'd presume they used AND only because its "different" to look at then &&, so its separates actual logical evaluation with shortcut evaluation.
    This syntax is valid for any non-language construct.

  • Users who have thanked Fou-Lu for this post:

    Coyote6 (04-20-2012)

  • #4
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Thanks for the replies... that is what I figured it was doing.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •