Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22316 invoked from network); 18 Nov 2014 20:30:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Nov 2014 20:30:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.182 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.182 mail-pd0-f182.google.com Received: from [209.85.192.182] ([209.85.192.182:35951] helo=mail-pd0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/B2-06737-18CAB645 for ; Tue, 18 Nov 2014 15:30:57 -0500 Received: by mail-pd0-f182.google.com with SMTP id g10so8985758pdj.27 for ; Tue, 18 Nov 2014 12:30:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=dDgu5DDRRBRNQiJ/l5vvnXaMoFJhaR1zGQBM2pShMyI=; b=Xys7WKeUhgasJ6nkz6Gfc+Tw9P6+R/b3tPkCHXFMl+5ENDpaonEcp61A2qV/optTXi kSIAPWxQIWXJ0Qb2QSHFGZ1w95LLr0bBjqlFlj40DeP60hdB23JzqfKzkr0wMV/MbzaO t4LKn1uynPIEg80ZOxOm08vQd3rZGoP+lpYG58cIAVxvRRcajSDQ62lPfnDMYEEC7xL/ seW7ilwQU2fEMVOZ6surs27gUOL5POucEnnfG5BwpWn8RXajptHL2wr+0ZezNugyHpMG a7amNjfCCf4H738z+ifLSWDguxuZzn68vACO5lAe4bIMaS+mB4mFc2xBR8sXcrKz2xoz KNsw== X-Received: by 10.68.57.167 with SMTP id j7mr12710563pbq.160.1416342654884; Tue, 18 Nov 2014 12:30:54 -0800 (PST) Received: from [192.168.2.145] (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id fn7sm8169539pad.38.2014.11.18.12.30.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 12:30:54 -0800 (PST) Message-ID: <546BAC7C.1030701@gmail.com> Date: Tue, 18 Nov 2014 12:30:52 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Alexander Kurilo , internals@lists.php.net References: <546B0F62.1090705@gmail.com> <546B9739.6060904@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Default constructors From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Does it *really* make sense for PHP? What if that parent class 'Animal' > from your example introduces a constructor that accepts, say, both > `$owner` and `$what` as mandatory arguments? `parent::__construct()` Then you need to rewrite all descendant classes anyway, this would be API change, not an API-preserving refactoring. Essentially, you take the Animal class and replace it with entirely different class with different requirements. You'll have to rewrite all the code that constructs Animal objects. This obviously is not the scenario I'm talking about (and of course nowhere near recommended practice for any maintainable code). > call in a descendant will appear broken (unintentionally, I suppose), > won't it? That'll work in Java just fine, though. In Java, you can not do that - if your ctor requires 2 arguments, you'd have to give it 2 arguments. If you still have the default ctor, that'd be fine, and so it will be in PHP - but in PHP you can not have two ctor functions, so in PHP you do things differently, we use optional arguments instead of using two functions. The meaning is the same though - if you're able to call new Foo(), you should be able to call parent::__construct() (or super() in Java case) on Foo. Except in Java it works and in PHP it doesn't. That's what I want to fix.