Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103896 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35494 invoked from network); 30 Jan 2019 18:51:22 -0000 Received: from unknown (HELO out1-smtp.messagingengine.com) (66.111.4.25) by pb1.pair.com with SMTP; 30 Jan 2019 18:51:22 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6462922331 for ; Wed, 30 Jan 2019 10:31:01 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 30 Jan 2019 10:31:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=XG4t03 Fbzv72y3ExxFy766htYi6+VCeZPS2JQjL8+VI=; b=IWEhVyNViTxNCWX+6Y5c3B Dz/Wffo0UV0AEHjeG6ADRvMLMpe2RTeEvC27foVlWhQX9D6rKdyQ+F3r2f+6IYat 11xNgBIRfQgv/LcCgI4bDOKlY6X+14FRamfo99IduKvyeL47j0k/JVmxgnaarz6t IdlYVEjtNhukV+7f0K4z3sojphOnARsTDHhFxU7m0tf5tBw9fRaaBIQfis06v9Fl JeiLuGz7Z9C2oXLRiFcsSrgvshkbJqCNPb1chX/HCAMxL9qLDbmevEKCIvi7qvr1 hx6nQ5Ot15evEo0bSZNFdxOrQ1nHQ4pm5o3m5km3Ej3Pgg07AcCvk4BZ0m4YW7xQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrjeeggdejiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucenucfjughrpefhvffufffkjghfgggtsehgtderredttddvnecuhfhrohhmpefnrg hrrhihucfirghrfhhivghlugcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtgho mheqnecuffhomhgrihhnpehphhhprdhnvghtnecukfhppedvudeirdektddrfedtrdduhe dvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggt hhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from vulcan.localnet (216-80-30-152.s3222.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com [216.80.30.152]) by mail.messagingengine.com (Postfix) with ESMTPA id A62DCE4662 for ; Wed, 30 Jan 2019 10:31:00 -0500 (EST) To: internals@lists.php.net Date: Wed, 30 Jan 2019 09:30:57 -0600 Message-ID: <3837033.kzX6na9RhK@vulcan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1797085.czvecCBsFR"; micalg="pgp-sha512"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV] Old style constructors in PHP-8 From: larry@garfieldtech.com (Larry Garfield) --nextPart1797085.czvecCBsFR Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Wednesday, January 30, 2019 5:41:45 AM CST Nikita Popov wrote: > On Wed, Jan 30, 2019 at 12:11 PM Dmitry Stogov wrote: > > Hi, > > > > > > I've just noticed that Wordpress-4.1 on PHP master started silently > > produce different output. > > > > The problem that PHP master started to ignore old-style constructors. > > > > They were deprecated in PHP-7 and PHP produced the following warning > > > > > > Deprecated: Methods with the same name as their class will not be > > constructors in a future version of PHP; ... has a deprecated constructor > > > > > > PHP master doesn't produce any warnings and just constructs a class > > without constructor. > > > > This silent behavior change may become a problem for porting legacy code > > to PHP-8, > > > > May be, it makes sense to emit fatal error in case of old-style > > constructor. > > > > > > Thanks. Dmitry. > > First of all, it is probably important to note that the RFC for this ( > https://wiki.php.net/rfc/remove_php4_constructors) explicitly specifies > that in PHP 8 methods with the same name as the class are interpreted as > ordinary methods and no warning or error is thrown. I've CC'd Levi and > Andrea, who authored this RFC. > > I think as an end goal, what the RFC specifies is preferable for a number > of reasons: > > * You should be able to call your methods whatever you like. PHP only > reserves the __ prefix for itself. > * The behavior is consistent with classes inside namespaces, where methods > with the same name as the class are treated as normal methods for a long > time already. > * The fact that a method has the same name as the class may be completely > incidental if it comes from a trait (see > https://bugs.php.net/bug.php?id=77470). The trait does not control in which > classes it may be used and which names those classes may have. Every Drupal 7 or 8 site includes classes that have a method name the same as the class name, on the assumption that it's safe to do for a normal method in current PHP versions. Making that suddenly a Fatal would be, er, bad. :-) As others have noted, this is easily solved with static analysis tools. There's been discussion of WP moving to a PHP 7-based version of PHP sometime this year (no promises, but that's the scuttlebutt), which would let them convert to __construct() universally and safely well before PHP 8 becomes an issue. --Larry Garfield --nextPart1797085.czvecCBsFR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE/ph/GXfY8v0YwFBp4MMKwDFxYXcFAlxRwzEACgkQ4MMKwDFx YXc2aAf/aroGKYVzxRmgdBuhAOMMLbZ00vcR5LJk3ZyWHfMV3F/f+eJ9Dqj4NY1n Bs4STXdOZkcZKwTfd0UFOr1SD+b9VEPhkCAzv/fRGcqJhaLdfaQgPKTKhm7mJGxd CL+gp2mO1rjbfx2GxGoax28OebI6n3Bov64LUY7dpIra8o9yM0LFWCSxNdBgQ9wA 2iPUi8Nn48YHq9S2i93+jCrkn4J0LPCVgNylQthc6G+cCAr4y9mADRDw36KFspIC 8VbTVAOl1rEcJxOo4ODMSxQH2pFM8M7PJS4NuhCuMK1HVVJHZAzL5ucnnt7/1BCC /JyhqRfG/ZQHR87WIAsImmdyDiqh4g== =3qT/ -----END PGP SIGNATURE----- --nextPart1797085.czvecCBsFR--