O
O
Optimus2017-08-23 16:14:40
PHP
Optimus, 2017-08-23 16:14:40

Why does the model return an object?

The code:

class newsView
{
    public function __construct($model)
    {
        //Это пришло из конструктора модели
        var_dump($model);
    }

    public function listmodel() {
        return 1;
    }
}

class newsModel
{
    public function __construct()
    {
        return 'Это вернула newsModel';
    }
}

class My
{
    public function showdata()
    {
        $model = new newsModel;
        $view = new newsView($model);
        $result = $view->listmodel();
        return $result;
    }
}
$obj = new My();
$res = $obj->showdata();

The response var_dump($model);shows:
object(newsModel)#32 (0) {
}

What's the point, why not a string? And where is the phrase
This returned newsModel
?
PS Run online https://goo.gl/xfuFXG and knows who else online demo is better than this wretched one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2017-08-23
Pyan @marrk2

The fact is that a constructor is designed to return an object and returns a new object implicitly, so there is no point in trying to return something through the constructor. There will always be an object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question