I have been following a very interesting tutorial that really tested my ability to program Php. I always thought that I am the man but I turn out to be the worse of the worse. Having said that, during the tutorial a requirement to instantiate an object was explained so I typed this code down and do not get me wrong everything works fine no problem at all. The major thing is that I do not really understand how thing work underneath that is why I would like some one to explain to me even more.
my question when you pull a record from the data base using MySQL_fetch_array what and how is the data presented to the receiving variable. for example bellow
private static function instantiate($record){
$object = new self;
foreach($record as $attribute => $value){
if($object->has_attribute($attribute)){
$object->$attribute =$value;
}
}
return $object;
}
if I have 3 fields in a table e.g Name, age, address and a value let say Jhone, 23, arizona what will be store in the attribute and what will be store in the Key and where is the index and how do foreeach extract such data from the database like the example above and assign it to the other array. please I do not need any codes my codes are working fine, what I need is a very primitive and clear explanation. and indeed thank you in advance for your support.
What really helps is to print out stuff in your methods (with
print_rfor instance). For example, try this with your method:That way, you can see exactly what is going on with the object, foreach etc.