Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vtxmg's avatar

calling parent constructor problem

When I call parent with Parent::_construct() or parent::_construct() on local host, it works. But in online only parent::_construct() works and look at there.. Shouldn't double underscore be there??? When I use double underscore it shows a error. so what is the really thing here?

error message

Cannot call constructor
0 likes
1 reply
jimmck's avatar

You are calling parent::__constructor() from an extended class inside its constructor?

<?php namespace App\lib\myutils;

use App\lib\myutils\apputils\mongo\MongoDocument;
use App\lib\myutils\apputils\mongo\MongoField;

class Address extends MongoDocument
{
    private $street;
    private $city;
    private $state;
    private $zip;

    function __construct($street= null, $city = null, $state = null, $zip = null)
    {
        $this->street = (new MongoField(MongoField::TYPE_STRING, MongoField::REQUIRED))->setValue($street);
        $this->city = (new MongoField(MongoField::TYPE_STRING, MongoField::REQUIRED))->setValue($city);
        $this->state = (new MongoField(MongoField::TYPE_STRING, MongoField::REQUIRED))->setValue($state);
        $this->zip = (new MongoField(MongoField::TYPE_STRING, MongoField::REQUIRED))->setValue($zip);
        parent::__construct($this);  // setup field value maps.
    }
}

Please or to participate in this conversation.