View Full Version : Non Operator use of the Word AND???

04-20-2012, 05:20 PM

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.

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

Here is the entire construct function in the class.

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);

04-20-2012, 05:42 PM
it's a logical operator,
$url AND $this->create($url); -- if both are true then will return true.


04-20-2012, 06:00 PM
The actual purpose here is to bypass an if check to call $this->create(). Its the same as doing:

if (!empty($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.

04-20-2012, 06:31 PM
Thanks for the replies... that is what I figured it was doing.