1

I have been wondering if it is possible to call function like this

//
public function getDataSource($id,$source,Request $request){

    $form = 'Invoice';
    $fuToCall = $source;

    return \App\Core\Forms\.$form.\.$form.DataSource::$fuToCall();


}

The concatenation of my $form name doesn't work, why? Can someone please help.

2 Answers 2

2

You're not really concatenating strings. The non-dynamic part of namespace in your example isn't a string.

You can do it like this:

$class = '\App\Core\Forms\\'.$form.'\\'.$form.'\DataSource';
return $class::$fuToCall();

Or with 1 line:

return ('\App\Core\Forms\\'.$form.'\\'.$form.'\DataSource')::$funcToCall();
Sign up to request clarification or add additional context in comments.

Comments

1

This should work.

call_user_func('\App\Core\Forms\\' . $form . '\\' . $form . '\\DataSource', 'fuToCall');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.