Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109953 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29259 invoked from network); 1 May 2020 16:28:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 May 2020 16:28:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2B5121804F3 for ; Fri, 1 May 2020 08:02:12 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 1 May 2020 08:02:11 -0700 (PDT) Received: by mail-qk1-f179.google.com with SMTP id c63so9482248qke.2 for ; Fri, 01 May 2020 08:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=fAtIEuKmLq2Bo69rah+ROayjcupuAxIfWAmxbXKsCBI=; b=W3s7Ky7t+b9NEmF2ACC/9Fouc/r025hgHV4XaplqKY5Hclg3kLPrysYUkxpRU0QABH +mt05Eub4ydKk8KKNanUJ9fu1hYvKe24qMofKRUIYRhb6ILwTKD/SvZOr/Y3XQQ1Q1l5 vKulXIBdeTfEP8Oex3och4z6Lbskib7Sa3h2xCOj4xRriLh/yTv4ozmeqNc6PU410gx5 5ZeEq2JWq546d1zhdiRZPMJG4QIOpjoYTEVq8bxOobW1aBPlYcy5RIhXCKrRjZVQZIHM wuHrERqAUJ9qCuMw9WTtgqXOE1WZ6XOVUmHa/q8NuQoZ7LeKKNxIcR+Aw6uNQaLn8F9m lxew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=fAtIEuKmLq2Bo69rah+ROayjcupuAxIfWAmxbXKsCBI=; b=Dt8ruLYTRrVyauglGof0yoRrN112xKHPYgxBWCGfdfPAnuVoNtJ6uDMejhW+zCn71t 1K8ysX+8e1qqRDqpewYhCH8UzTKxE0+KwioWJ31BRaumQgw6nKQYfFem5MES/M4Tv6RJ 6pBjTk+VUEm7FRCZElwaZgFyB/hKSyxg6N581Wyx2Vpx1Dp/rPke9ERrFDRzHR7H0NfY jrT+E/o9ZnhdIKrdJ8eGcGUVA47Zk1g0+kL4qqm8y8LEGQiLzezWDYIbNpzKTofOUZiB ADXxgiX25iRcu+S1qNcDjAx2KwLtbff9iunRg1Xrt/rBfd2eT/gb7S4VjapjzGWZrDkl jMPA== X-Gm-Message-State: AGi0PuZdTpeGocUUmPf6eBi6kOzU+8I8RXX7h70wyxK48AH2jMv0Ft9q aTjDM9UNS3GoqsV8k2ZjUP6fCpDrOrA= X-Google-Smtp-Source: APiQypKAAC1ti3fM839Pl0LLlms5y1g9YBekyqooUdiKq166qwBIWAfyIlBfw76ORb7NJqQH1dsQYg== X-Received: by 2002:ae9:eb8f:: with SMTP id b137mr1510099qkg.192.1588345330358; Fri, 01 May 2020 08:02:10 -0700 (PDT) Received: from [10.10.42.56] (h96-61-170-50.lvrgtn.dsl.dynamic.tds.net. [96.61.170.50]) by smtp.gmail.com with ESMTPSA id o68sm2752887qka.110.2020.05.01.08.02.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2020 08:02:08 -0700 (PDT) Message-ID: <647703CF-1015-4FBF-868F-8E3525706A43@benramsey.com> Content-Type: multipart/signed; boundary="Apple-Mail=_0776B4DD-81C3-4B6A-855F-CC2953371BAE"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Date: Fri, 1 May 2020 10:02:06 -0500 In-Reply-To: Cc: internals@lists.php.net To: Max D References: X-Mailer: Apple Mail (2.3608.60.0.2.5) Subject: Re: [PHP-DEV] Simplify classes syntax proposal From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_0776B4DD-81C3-4B6A-855F-CC2953371BAE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On May 1, 2020, at 09:44, Max D wrote: >=20 > Greetings, Internals! >=20 > This is my first try to input the proposal, please don't be strict ) >=20 > All the years with PHP I hate writing classes. The need to prefix = EVERY > property and method use looks horrible and writes horrible. So, the > proposal: >=20 > Lets introduce directive > declare(simple_classes=3D1); >=20 > This directive will switch interpreter mode, where class declared > properties and methods are accessible as regular variables and = functions at > class code. >=20 > So, such a fragment >=20 > public function __construct() { > $this->get =3D $this->clean($_GET); > $this->post =3D $this->clean($_POST); > $this->request =3D $this->clean($_REQUEST); > $this->cookie =3D $this->clean($_COOKIE); > $this->files =3D $this->clean($_FILES); > $this->server =3D $this->clean($_SERVER); > } >=20 > will look so with the proposed directive: >=20 > public function __construct() { > $get =3D clean($_GET); > $post =3D clean($_POST); > $request =3D clean($_REQUEST); > $cookie =3D clean($_COOKIE); > $files =3D clean($_FILES); > $server =3D clean($_SERVER); > } >=20 > What do we lose with such an approach? The ability to use local = variables > named as class properties and the ability to call regular functions, = called > as class methods. Both things are super-rarely used and programmers = have > the ability to change naming to achieve them. >=20 > For static properties/methods, dynamic ones will have an advantage if > naming matches. > Of course, the ability to use usual prefixes will be preserved. >=20 > I'm not going to implement this, hoping someone will volunteer if the > reaction is positive. > Also I have some more proposals I will post if this one goes nice. >=20 > With best regards, > MaxD Hi, MaxD! Is there a particular problem you=E2=80=99re trying to solve with this = proposal? You say, =E2=80=9CAll the years with PHP I hate writing = classes. The need to prefix EVERY property and method use looks horrible = and writes horrible.=E2=80=9D I=E2=80=99m generally in favor of changes that make it easier for = developers to do their jobs well, but I don=E2=80=99t think writing = `$this->` in front of property and method names is a detriment to the = development process. In fact, I think it aids in writing safe code. = Without `$this->`, it=E2=80=99s possible to unknowingly use or overwrite = a class property, when that is not the intent. I think this leads to a = poor developer experience, so I would be against this change. Cheers, Ben --Apple-Mail=_0776B4DD-81C3-4B6A-855F-CC2953371BAE Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCXqw57gAKCRCwLZeYnIwH G2XJAP4wr0yLinDl1DvDRLVH3yEIYBUYgGoJp2VdWDQ5MZlz2wEAkZF85nt3VqsB zNaCuWcj50jaXtuL7EJbYWa2EEFek4g= =k8JJ -----END PGP SIGNATURE----- --Apple-Mail=_0776B4DD-81C3-4B6A-855F-CC2953371BAE--