php - Combine method calls into one single call
Get the solution ↓↓↓So I have the below two methods inside my class:
private function set(string $id, object $set): bool
{
return update_option('o_' . $test, $set);
}
private function save(string $id, object $r, object $set): bool
{
return $this->set($id, $r);
}
Then I'm calling them as shown here:
Is it possible to call using one single method as such?$this->save($this->set)
etc.. They're using the same $id and $set, but one has a $r added.
Answer
Solution:
No.
Conceptually, each method is replaced by its return value. But you don't want to have the return value of one function as the parameter in the other, so you cannot do that.
You can nest function calls if that is the case, for example with the following functions, which all take a string as their argument (I have made up the function names):
uppercase(substring("Hello World!", 0, 5))
Which would return "HELLO". Here thesubstring
function returns a string, which acts as a parameter to theuppercase
functions.
However, as you also callset_settings
at the end ofsave_settings
, the second call seems superfluous.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: constant expression contains invalid operations
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.
Similar questions
Find the answer in similar questions on our website.
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.