I was wondering if it is bad convention to declare my member variables inside an array that I later use somewhere else (in the code below, I pass into the insertArray() function). Here my code:
class myClass{
private $ID;
private $name;
private $type;
private $catID;
private $isDefault;
private $isRequired;
function __construct($compID = 0, $catID = 0, $name = '', $type = '', $default = false, $required = false){
$myArray = array(
'name' => ($this->name = $name),
'type' => ($this->type = $type),
'catID' => ($this->catID = $catID),
'isDefault' => ($this->isDefault = $default),
'isRequired' => ($this->required = $required)
)
self::insertArray($myArray);
}
}
Is it bad to define my member variables inside $myArray? I'm pretty sure in php that syntax of the form ($this->value = $value) will store $value inside $this->value and then just evaluate to ($this->value).
If it's bad or not depends on the coding guidelines you follow. Most of them allow only one operation per line but you have two.
Take a look at the PSR-2 standard for example.
It's also not that easy to read because it's not common.