Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112083 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85345 invoked from network); 20 Oct 2020 23:43:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Oct 2020 23:43:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AEE201804C3 for ; Tue, 20 Oct 2020 16:00:45 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2038.outbound.protection.outlook.com [40.92.18.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 20 Oct 2020 16:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SlPyCromUNk024wkF2bPCEbzjLGjtcuKALTNhAyK454Ump+ymKYyYkVeh+X1tQjfJaFpb/t/awpU+wRgZCuxSG3FFEFpTSlYRL5JJxTtcNmL1d4BS3IBWDIRVuU+ayN1v3tcd/z4BHSVRhsbBoKkYMOhvG6hC3qBByHbPuMPFYyX/Pyt3FIhACQ59sGjS3aVkDOgGz1gu5NClZK9kS4R3Zez3IDHdg6p03mnBCx8gBkaAajXHA/2HdTOZROFdOgnJGCyyvddeqNkBXaztj6rFZVK/8AzMgkGN87ZK6zzMOVCp5rSci8ayMyyGZVhu0veDVFdPc/jHP917FFKwUI9hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2qAmB+1B2DRm7yFNEc3lt7NB9Prvo6BFm4OkW8JS+Iw=; b=ewCkdrroy/ZaIq8WGq2KI3lrNNbOI2rkZ7xwymspNZQo5hISyNZi3oPnlMs7UO8hrx+osgDY42TtysU9h0zIQyo+E3V4y9iiGlDnGNbVIL9jbUL26n2kkkN/6hTVOafd9Jwgh3zvTB8RDBBFQ0rCLoyUh3tiQA0g9bliLtaXmLbB3FqkjFUDb7f9XlZdySnFicREsvncAoSeICJ0y+VrXcknljsnu3sCUuUVZta+YDvBi3/HrodtljWPFXQ385rQgBfzDp/5W/x3cwJzDBB8+IAamLGb9Pj/b9z9HeBUw+Z05NwQe5JksEIkcbGAcPfrZtkQMHPXbD/NDp+c3iVxpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2qAmB+1B2DRm7yFNEc3lt7NB9Prvo6BFm4OkW8JS+Iw=; b=VKavkjZjqvZUdMxUuSEW64TEGv3hrCxZ0x0BGgofKm8AZhshy7ftBtyvUAn5R2nMLIrFmlafNFCkOYBdwIX7PxgwONOcj2ovb5r6fO0pJhuBFDvAnNPf4UFJgUnsFuLA2bTcNds8QJkDpxnhbfMxxsk15OVIyrgsVd2KHR6ciPPrTnR3yIN7d48+SkLpEDinutC3KJOAGJP74e9yJPSdvOngB/b4baux8d803/w0486fiNuxtCPipBLrRlfRBT4lYQXMhJ/1WbgpqZxZHdy1Jdl0ihsDqkzrjEWB4F0Gd74/ElWVYBsNQ8w9xmbtutEXt0V6sU2jlz9lO3gLyHq02g== Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::50) by CO1NAM11HT214.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::480) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.23; Tue, 20 Oct 2020 23:00:43 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:3861::43) by CO1NAM11FT058.mail.protection.outlook.com (2a01:111:e400:3861::164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.23 via Frontend Transport; Tue, 20 Oct 2020 23:00:43 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::d99c:15a8:f595:d00]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::d99c:15a8:f595:d00%7]) with mapi id 15.20.3477.028; Tue, 20 Oct 2020 23:00:43 +0000 To: "internals@lists.php.net" Thread-Topic: Idea: Warning about named parameters with a missing constructor? Thread-Index: AQHWpy9JfEcggMAw+ka3piJ2WMOckQ== Date: Tue, 20 Oct 2020 23:00:43 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:DB92A85CA672FE1114FC9DEF37EF448C734B6D19AAC1E175C89A81A60A95A196;UpperCasedChecksum:0A70420D6631A3212FC5EDC5F6127E175C07D7A8B917250965C4E18B32151584;SizeAsReceived:6833;Count:41 x-tmn: [zhqblcfy/UNe3SVwoaVvu0XtXy/s/9stQ1A1yYMgpLuUarO4BETk5N7ORAu8zbup] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: cf364b8e-a752-41d4-cec8-08d8754bf954 x-ms-traffictypediagnostic: CO1NAM11HT214: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nzrjlpOAeJ5J+q2I8FrA75SRc7KPNWMn5p5PwzLshSc0pPLR++wW4APOR5PTwUnqDeh8kRjOAPPdSEvR7hOtkbukual/cF3oaJ4s+wqyRA/cwo8k7h+xcnSil/QHlNycoQBA7XfSg5rLlA94jfBJWdjp2krIhuc7Pmpfdk3P2T/v64Yc9LUjVumEUffISYdkp5tijEXm+hv8iLet/+h5VZAd0l3OGQCPxM/Ko8k/6gqioLyndRhBRg2JCYjSCH0Q x-ms-exchange-antispam-messagedata: 1omeM2G9UOXDUqYJ7udA4SL7Xnae8rpBSiEASzL5wajIUwRagGEsnT19tHrjGSOf0O8jtKE9MixY2XzgOAICcbYS6ZFrOJRH973rIaYHeWXBVxa1eQxY5NK4laZ2gcSdloTIidC8YnlWjNBYnlFEec+Ik+TUTw7GtBh1TRmLt9d/GEDWhS7tuNA6bs+po8kBXvfsuP3qb9751+P/H18qzw== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: cf364b8e-a752-41d4-cec8-08d8754bf954 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Oct 2020 23:00:43.8527 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1NAM11HT214 Subject: Idea: Warning about named parameters with a missing constructor? From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= Currently, if there is no constructor, php handles it just like `__construc= t(...$args) {}`,=0A= both for positional and named parameters. Is there any interest in changing= that to be a deprecation warning if one or more parameters are passed?=0A= (or if 1 or more named parameters are passed)=0A= =0A= The default behavior of missing constructors would result in somewhat surpr= ising behavior=0A= for `new $className(paramName: 123)` if this was used unexpectedly=0A= (silently ignoring it)=0A= (Desired behavior would be to deprecate/warn/throw)=0A= =0A= ```=0A= php > class A {}=0A= php > var_export(new A(paramName: 123));=0A= A::__set_state(array(=0A= ))=0A= php > var_export(new stdClass(paramName: 123));=0A= (object) array(=0A= )=0A= php > var_export(new stdClass(123));=0A= (object) array(=0A= )=0A= ```=0A= =0A= (I don't think https://wiki.php.net/rfc/named_params mentioned this=0A= (the current behavior follows from handling of extra positional parameters)= ,=0A= and this mistake is probably unlikely in practice,=0A= but if it were to occur it would very likely be a bug)=0A= =0A= PHP already throws ArgumentCountError for passing too many parameters for i= nternal methods=0A= so the default method not throwing is a surprise. I haven't yet looked into= how much code would break if this were changed.=0A= =0A= Aside: If a static analyzer such as Phan, Psalm, or PHPStan are set up, tho= se bugs could be detected easily,=0A= so the impact seems low, but I wonder if this type of bug could cause confu= sion (or feel unexpected)=0A= for those who are more familiar with other languages than they are with php= .=0A= =0A= Thanks,=0A= - Tyson=