Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80702 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94767 invoked from network); 17 Jan 2015 17:56:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jan 2015 17:56:24 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.41 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.218.41 mail-oi0-f41.google.com Received: from [209.85.218.41] ([209.85.218.41:33760] helo=mail-oi0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/A0-24029-642AAB45 for ; Sat, 17 Jan 2015 12:56:23 -0500 Received: by mail-oi0-f41.google.com with SMTP id i138so21717474oig.0 for ; Sat, 17 Jan 2015 09:56:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=ZYNQS4yHNhecC6V1CrkeK++BgATHDhD1p+yyX5rOysY=; b=nI8hbG2Zxu94TK455TZ7SeEf3JSERUXynR9XReXXXkYy4W8xn+Rx37DwinTjC7ON3r Gl3+C0hnwdmGO+a10ueLoBkvrhffYTD9g3kVb15S4K4USTOv4FS3JYZ2qon5IN0cGbvg EYwQ2Fhq4RhLeTfqXQK7UaLPXPV+1zlRKQewgJ3mu6Nj9ywwqBcup8S+pozQzItIqBb2 CD1pxUBWc7Zkjf0X1aTNVxUFICXKWj1c1PPaZHCDA5ljJ90Ik4wa01kSFQRF6NT165Hv UM7lerx30BUF45yp1qpckqRm9wAc6aPLG38EgcASM11iwPy9WyXNSwLDNPpUHEmh1nq4 wMAg== MIME-Version: 1.0 X-Received: by 10.182.215.163 with SMTP id oj3mr13365333obc.49.1421517380081; Sat, 17 Jan 2015 09:56:20 -0800 (PST) Sender: morrison.levi@gmail.com Received: by 10.76.103.101 with HTTP; Sat, 17 Jan 2015 09:56:19 -0800 (PST) In-Reply-To: <78.22.47555.7C24AB45@pb1.pair.com> References: <0DD30A0D-E7CA-4150-83E0-8FD46635279C@ajf.me> <8761c6280g.fsf@margaine.com> <54B91D16.70901@gmail.com> <78.22.47555.7C24AB45@pb1.pair.com> Date: Sat, 17 Jan 2015 10:56:19 -0700 X-Google-Sender-Auth: AVJOToSmrdcs4bP7HvKwEvS_t10 Message-ID: To: Tony Marston Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Remove PHP 4 Constructors From: levim@php.net (Levi Morrison) >> We are talking about something deprecated since 10 years, about the 1st >> major release in a decade, something we will use for the next 12-14 years. > > > That is the point - PHP 4 constructors have NOT been marked as deprecated in > the manual, and they produce no warnings at runtime. > > If they have not been marked as deprecated then you cannot suddenly remove > them. Warning: a long response with code snippets/ See this code (http://3v4l.org/ViPpb): class Test { function test() { echo __METHOD__, PHP_EOL; } function __construct() { echo __METHOD__, PHP_EOL; } } new Test(); Note that there is an E_STRICT generated for having both constructor types in all versions of PHP 5 and that `__construct` is actually used as the constructor. Now if you change the order of the definitions around (http://3v4l.org/BhPMm): class Test { function __construct() { echo __METHOD__, PHP_EOL; } function test() { echo __METHOD__, PHP_EOL; } } new Test(); Note that `__construct` is still used and the E_STRICT is only generated in PHP 5.0-5.3 (roughly; it's a bit more nuanced). If you put a namespace at the top of the first example(http://3v4l.org/hWFnC): namespace NS; class Test { function test() { echo __METHOD__, PHP_EOL; } function __construct() { echo __METHOD__, PHP_EOL; } } new Test(); Then there are no warnings of any kind (since PHP 5.3.2), and __construct is used as the constructor. The method test is just a normal method. To me this clearly indicates three things: 1. Having both forms of constructors is bad form (hence the E_STRICT) 2. When both are present the new-style __construct is used over the old-style PHP 4 constructor, meaning the language prefers __constructor. 3. Old-style constructors don't exist in namespaces. Notably this was a conscious choice as evidenced by behavior that existed in PHP 5.3.0 - 5.3.2 where the E_STRICT was emitted like non-namespaced code. This is the behavior of shipped, stable versions of PHP. I think it's a bit illogical to conclude that just because there aren't any E_DEPRECATED warnings emitted in PHP 5 that old-style constructors are fully supported. That leaves us realistically with four options: 1. Bring full support for PHP 4 constructors 2. Emit E_DEPRECATED when PHP 4 constructors are used 3. Drop support for PHP 4 constructors so they are just normal methods, just as they are in namespaces 4. Maintain current behavior. As already mentioned I think as an end result we shouldn't have two ways to define constructors. Given that PHP already prefers the new-style constructors I've proposed that we work towards dropping the old-style, it's just down to a matter of how.