php - Object of class charts could not be converted to string

831

I have written a class for which the constructor function has 3 arguments. In some function of the class I have to query from db like this $profit_row->operating_profit.

now instead of writing operating_profit, I want to pass it as a variable to the constructor of the class. So my whole variable becomes $profit_row->$this->num where $this->num is initialized in the constructor.

When I do this I get the following error. How to go about this. Object of class charts could not be converted to string

662

Answer

Solution:

Maybe this is what you are looking for?

$profit_row->{$this->num}
899

Answer

Solution:

$profit_row->{$this->num}

you have a precedence problem.

People are also looking for solutions to the problem: php list array by random date

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.