Best practices question: Is there anything improper about creating a new object within another class method? I have a small example below:
public function export() {
$orders = new Orders($id);
$all_orders = $orders->get_all_orders();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The example you gave is perfectly acceptable.
If for example, you were instantiating the same object in all of your methods then you could store the object as a property instead.
Example: The Orders object is instantiated in the constructor and stored as a property.