r/PHPhelp • u/silentheaven83 • Jun 17 '23
Understanding Array vs Object
Hello everybody,
sorry if it's a dumb question but I need your help.
Between these two solutions for saving a Book after a form submit:
// book_submit.php
$BookMapper = new BookMapper(
$Database,
$Log
);
$Book = new Book();
$Book->title = $_POST['title'];
$Book->summary = $_POST['summary'];
$BookMapper->insert($Book);and
// book_submit.php
$BookMapper = new BookMapper(
$Database,
$Log
);
$BookMapper->insert(
array(
"title" => $_POST['title'],
"summary" => $_POST['summary']
)
);
// Or even
$BookMapper->insert($_POST);which one is considered the best and why?
The BookMapper class will return a Book object from its select() method, here I'm only talking about saving data.
Thank you
9
Upvotes
2
u/whoisthis238 Jun 17 '23
$BookMapper->insert($_POST)This is massive security hole.