O
O
onogur2014-05-06 08:48:56
PHP
onogur, 2014-05-06 08:48:56

OOP: Storing an object in a property of another object?

Such is the task. For example, I have a PDO object. I create it in the constructor of the main class and assign it to a property of this class to access it from other methods of this class. In the future, to pass it to third-party controllers through action arguments, like this:
$Obj->actionName($this->MyPdoObj)
Question: am I doing it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2014-05-06
@onogur

Everything is OK, no set of objects is created, links to the same object are stored.

L
Lubaev, 2014-05-06
@Lubaev

You can probably use a getter to access this PDO, rather than passing this object every time you need it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question