A
A
atis //2016-11-30 12:17:02
PHP
atis //, 2016-11-30 12:17:02

What is the best way to pass methods to a function, in the form of objects or values?

So.
It is necessary to create an order on the site using the Market::createOrder() method.
Think about architecture. What is the best way to get parameters. As objects or values.

class Car extends ActiveRecord
{
  protected $id;
  protected $name;
}

class User extends ActiveRecord
{
  protected $id;
  protected $name;
}

class Market
{
  public function createOrder(Car $Car, User $User)
  {
    // не нужно проверять существование в бд

    // executing ...
  }

  // OR

  public function createOrder($carId, $userId)
  {
    // нужно проверить на валидность

    // executing ...
  }
}

Here's what I think is the best way to do it.
To check through PHP or foreign key in a DB to make. That's just a lot of headaches with them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Vitaly, 2016-11-30
@atis2345

My personal opinion: use objects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question