I'm using PDO to fetch rows to object. I have two question about that:
1- Using private properties in object and returning them using __get() method which may call another function itself for example getLabel(), how this affect php performance when retrieving a lot of records? Is it acceptable?
an example:
class model
{
private p1;
public p2;
function __get($name)
{
return $this->{'get'.$name}();
}
function getP1()
{
return '';
}
}
$obj = new model;
$obj->p1 VS. $obj->p2
2- For class with many columns, defining all those columns in the class definition, then selecting some of them when retrieving a lot of records, how this affect php memory usage as they are defined in objects with null values? is it acceptable?
I don't fetch the rows one by one and not all at once.
an example:
class model
{
public $p1 = null;
public $p2 = null;
public $p3 = null;
public $p4 = null;
public $p5 = null;
public $p6 = null;
public $p7 = null;
public $p8 = null;
public $p9 = null;
public $p10 = null;
}
sql: select p1, p2 from model limit 100
each object has 8 unused property. how this affect php performance and memory?
As much as I know doctrine use these two patterns. how do they overcome this affecting php performance?