0

is it possible set method variable default value if variable is expected to be "new class"

class controller{

    function getData(client $client){
    }
}

$c = new controller;
$c->getData( new client );

TO SET DEFAULT VALUE LIKE

class controller{

    function getData(client $client = new client){
    }
}

$c = new controller;
$c->getData();

1 Answer 1

1

No, it's not possible. You should implement this behaviour in the method:

class controller{

    function getData(client $client = null){
        if (is_null($client)) {
            $client = new client;
        }
    }
}
Sign up to request clarification or add additional context in comments.

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.