Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103893 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76669 invoked from network); 30 Jan 2019 15:02:26 -0000 Received: from unknown (HELO mail-it1-f178.google.com) (209.85.166.178) by pb1.pair.com with SMTP; 30 Jan 2019 15:02:26 -0000 Received: by mail-it1-f178.google.com with SMTP id g85so9773651ita.3 for ; Wed, 30 Jan 2019 03:42:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=55NaL6jkaaKEmTDgt/b64ODjdBJQ3tAVHzbbKsC6npc=; b=q8REa0iABUc028il5gZY8sLq9FsUXlNE5LClmrMBpTCMXMs69doAaUH3PXPAVRP2y3 r6FedFVM3O68kBZJxJyASB7z+nOEc8I2XOHHuQTXZPRLPT56EHb8ogMkg5wwx3F/6r13 JmsAgyedTAwaumUcMCJMKNaxr6B9dzT11sksXxj3BVdh+jX4TgyDuY7C/pIub0eB+q0f hQcaFLnGXvTgVNqzVS9lge1xi0scDxZtPd/FBSOsxCTHxECw0ci++/+kuqEhPSUZ56qk +TLRdPLVOJKo/5HSQAMvrqPPVUXwPorKV6+ju94bwWJXVb9PbEIh3oB0dFRBpxkIFo+d f6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=55NaL6jkaaKEmTDgt/b64ODjdBJQ3tAVHzbbKsC6npc=; b=EvE67GquM+vGZJPqeuPLKCrDg5yj2hALxVDxEaTqqJhAXV2SgUNmIS84EIdzY6o3EK f/wgOyLL9R1/Kor739M7rvoh147WFh3c1VVm6qrxpI96kCQD1BLx3zOD6/SzfWOwQbSD ynuAIgLeQZuE7OpWynZ1OKkIVVX5q89xXS/NTINK8CF+fMzWJixP/OT+Iud6tZ3YLxy5 iySG+aXhphBjWl0bWyr5rSWx6YUJWutXadNcqk1LShwXbjKF6Xavx8oU8sZRi3Pq7d8r L4O1D1A95oVGB2lynKesVIg14ufE3VF/nb17a7GHHmlB0wZWks4ytUwX6vqSlVWrV34p X4WA== X-Gm-Message-State: AJcUukfH9ffuaC4ovQDda66RYtWKUbPgR4dn60+V3VzvSXYu1BI9i6fd OlzHAZpSUEnIEaxVtgEhiKjkqsoJOw9Z8BWchGv1LbMF X-Google-Smtp-Source: ALg8bN4etK0uVaGxyZyrNZXZFyAJBwuRprgMQJMFFps1gRbWJUXVtRU/+19HHknEtSoZmeILo15/ASvMN/2qG0Cxc4k= X-Received: by 2002:a02:410e:: with SMTP id x14mr17551758jaa.36.1548848523079; Wed, 30 Jan 2019 03:42:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 30 Jan 2019 12:41:45 +0100 Message-ID: To: Dmitry Stogov , Levi Morrison , Andrew Faulds Cc: PHP internals , Nikita Popov Content-Type: multipart/alternative; boundary="0000000000000776a70580ab66c0" Subject: Re: [PHP-DEV] Old style constructors in PHP-8 From: nikita.ppv@gmail.com (Nikita Popov) --0000000000000776a70580ab66c0 Content-Type: text/plain; charset="UTF-8" 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. Of course, porting of legacy code is a legitimate concern. I think the relevant question in that regard is: How likely is it that people will port code directly from PHP 5 to PHP 8, without ever running it on PHP 7, where this generates deprecation notices? Not very, I think. Finally, it should be mentioned that finding old style constructors is trivial with static analysis, and I believe that a lot of code style checker and analyzers already support this functionality since the release of PHP 7.0. Nikita --0000000000000776a70580ab66c0--