PHP – Variable Assignment (short-hand)

By | February 28, 2013
/** Short-hand Assignment **/

// below statement means if not null $this->psql do nothing else assign $this->psql = Database::instance('psql');

$this->psql or $this->psql = Database::instance('postgresql');

// above statement same as below

if(!$this->psql)
{
   $this->psql = Database::instance('postgresql');
}

// or same as below

if($this->psql)
{
   // do nothing
}
else
{
   // do assign
   $this->psql = Database::instance('psql');
}

// or even same as below

if(empty($this->psql))
{
   $this->psql = Database::instance('postgresql');
}

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 12 =