No dobrze, ale są jakieś konkretne wytyczne kiedy używać jednego zapisu, a kiedy drugiego?
Których z zapisów jest bardziej poprawny, czytelny i zalecany w następujących sytuacjach?
Sytuacja 1:
//1.1
//1.2
else
//1.3
Sytuacja 2:
//2.1
$type = (substr($type, -1) == 'y') ?
substr($type, 0, -1).'ies' : $type.'s'; //2.2
$type = substr($type, 0, -1).'ies'; else
$type = $type.'s';
Sytuacja 3:
//3.1
return (isset($this->$key) OR
isset($this->data[$key])) ?
TRUE : FALSE; //3.2
if (isset($this->$key) OR
isset($this->data[$key])) return TRUE;
return FALSE;
//3.3
if (isset($this->$key) OR
isset($this->data[$key])) return TRUE;
else
return FALSE;
Sytuacja 4:
//4.1
return (isset($this->$key) ?
$this->$key : (isset($this->data[$key]) ?
$this->data[$key] : NULL)); //4.2
return (isset($this->$key) ?
$this->$key : (isset($this->data[$key]) ?
$this->data[$key] : NULL));
//4.3
return $this->$key;
elseif (isset($this->data[$key]) return $this->data[$key];
else
return NULL;
//4.4
return $this->$key;
else if (isset($this->data[$key]) return $this->data[$key];
else
return NULL;
//4.5
return $this->$key;
if (isset($this->data[$key]) return $this->data[$key];
return NULL;
Sytuacja 5:
//5.1
return isset(self::$instance) ?
self::$instance : self::$instance = new self; //5.2
if (isset(self::$instance)) return self::$instance;
else
return self::$instance = new self;
//5.3
if (isset(self::$instance)) return self::$instance;
return self::$instance = new self;
//5.4
if (!isset(self::$instance)) self::$instance = new self;
return self::$instance;
Które z nich, a może jakieś inne są najbardziej poprawne?