Question about "->"

Asked

Viewed 28 times

0

Good morning, I have the following code snippet:

$sql = "SELECT * FROM users WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_email . "';";
            $query_check_user_name = $this->db_connection->query($sql);

db_connection would be: $this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

My question is this, the variable $query_check_user_name receives the db_connection variable for the current instance that receives query($sql)?

How would that look without the "->"? And with the "->" how does the process work? (who receives who)

1 answer

0


It will receive the return of the method query(). Simply that.

It depends on the scope of your class, whether this method is return __toString or etc.

It is possible to make return of the class urge by giving return $this in the method invoked.

I did not understand very well the doubt to be honest, it was poorly formatted. But what I understood I answered.

In invoking

$query_check_user_name = $this->db_connection->query($sql);

You basically are saying:

PHP, all good?

I need you to access object db_connection of this class, in this object will have another instance, in that instance you will invoke the method query and inform $sqlas argument. The return of query() you store for me in the variable $query_check_user_name please.

  • Sorry I got badly formatted.. But this is exactly what I needed! Thanks Junior, completely clarified my question.

  • @rasec I am glad to have answered. Needing only to come back here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.