trying to develop a class associated with table(like in frameworks). assume we have a class named Book
class Book
{
public function save()
{
....
}
}
$book = new book;
$book->id = '1';
$book->name = 'some';
$book->save();
the problem is how can i access this dynamically created properties inside save() to save new record
You could do it that way (note that there are other solutions to this problem) :
public function save() {
$properties = get_object_vars($this);
print_r($properties);
// do something with it.
}
You can find properties in an object with:
$properties = get_object_vars($book);
here is complete code that you should use:
<?php
class Book
{
public function save()
{
$vars = get_object_vars($this);
var_dump($vars);
}
}
$book = new book;
$book->id = '1';
$book->name = 'some';
$book->save();
?>
</div>