Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109955 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36476 invoked from network); 1 May 2020 16:52:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 May 2020 16:52:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 369E41804FD for ; Fri, 1 May 2020 08:26:38 -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.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL 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-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) (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:26:37 -0700 (PDT) Received: by mail-vs1-f53.google.com with SMTP id l25so6485646vso.6 for ; Fri, 01 May 2020 08:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bukrek-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Uxmrrti5l4Q8eJmAyu0PSD/hD5eV+L0cfbHYVdna9mk=; b=GJhvv/0HJpchfyAkRriZLLFBAmsRGYRdeNVTnx2F9uWX7hObB9kFwzrdnfl/PwB7QV ixVvHbsOZ9poKMZ7f4FVY+XKjxFAJExElDHX3HdMcyYqPgPDm3klgqgopx3ABluNXxhU 7Hpomaliwymg0VmrJ7utYQLBf5Tf+tfmpdlSaGGe3l2yprO410EVRLO3QPmZOPYLyZtJ 18hIT2W4ohEcdTyCnPZZ+Xd4XYKUGwSb5KeEnqMEvAIrOFrtraCK+Gia1TPzAD/MiFet SqXMXRT2bx0ZbItUX4lpQJvMLPtOyG4JMyBS6L/f35gJdkS8D/dWM6n4A6O/h4a/sPTc 8Tyg== 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=Uxmrrti5l4Q8eJmAyu0PSD/hD5eV+L0cfbHYVdna9mk=; b=fe22aj9dIj7YRSRrQ0pNhvbCRA/H+9UCQZQxwvGQE39AAJ6PkPv6Hsz/69Ay2mabFR bbmQSCQBy4c+VaGrMMYr5GIsmTP2XO0gOUl97shlAtihpO0HI/wG56tUsRfbMZqcumpY 1VmizWwbWbGRRyK0I5DevsMREpO9zcyv9raZLp18cWkzuaueNz3qCVwNSgY+pVnvzEPa rQObDeX1nWHInW7KU5Ilh+L1FtEMrmAw0zJ3l5eRZc56I5P1iJAKtHne/8t9DGrv1GNb MsGxqn5sK/e3ALmJ+OihXgGx1fnGfhP/eRR7CNe4rMNUvsfZJcydTv18wqhvQkaZqBpk sErQ== X-Gm-Message-State: AGi0PuaZIJjipiwZC17VBiJW5x8enCMuXxfiHOfOT1LqC0ztjJ8dvuDT 6koWpTw9ltG1v63szVVVMrHtPQO/T6ji/C9HNUqb7w== X-Google-Smtp-Source: APiQypJcyfCvqQFX30YLWkKa6kqMYffCTNsbFshoV/4TwFZtrV9Y37w/XZPjjBvlRrJAYfBXEL0zBZPL6ejTfywRiH8= X-Received: by 2002:a05:6102:446:: with SMTP id e6mr3840389vsq.68.1588346796773; Fri, 01 May 2020 08:26:36 -0700 (PDT) MIME-Version: 1.0 References: <647703CF-1015-4FBF-868F-8E3525706A43@benramsey.com> In-Reply-To: <647703CF-1015-4FBF-868F-8E3525706A43@benramsey.com> Date: Fri, 1 May 2020 18:26:24 +0300 Message-ID: To: Ben Ramsey Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000009a288305a497ce89" Subject: Re: [PHP-DEV] Simplify classes syntax proposal From: max@bukrek.net (Max D) --0000000000009a288305a497ce89 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you for the replies! Take note, that this directive is optional, so it will be used by programmers that would like this coding style. Of course, it will make code reading more challenging. But, from the other side, code will look more clean and human like, making understanding the logic easier. Now it looks like some core dumps, especially with *self::* prefixes. Without syntax highlighting it's barely readable. Just to mention, C++ and Pascal have such simple referring scheme without alternatives. Millions of programmers write and read such code from the beginning of classes up to now. With best regards, MaxD =D0=BF=D1=82, 1 =D1=82=D1=80=D0=B0=D0=B2. 2020 =D0=BE 18:02 Ben Ramsey =D0=BF=D0=B8=D1=88=D0=B5: > > On May 1, 2020, at 09:44, Max D wrote: > > > > Greetings, Internals! > > > > This is my first try to input the proposal, please don't be strict ) > > > > 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: > > > > Lets introduce directive > > declare(simple_classes=3D1); > > > > This directive will switch interpreter mode, where class declared > > properties and methods are accessible as regular variables and function= s > at > > class code. > > > > So, such a fragment > > > > 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); > > } > > > > will look so with the proposed directive: > > > > 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); > > } > > > > What do we lose with such an approach? The ability to use local variabl= es > > named as class properties and the ability to call regular functions, > called > > as class methods. Both things are super-rarely used and programmers hav= e > > the ability to change naming to achieve them. > > > > For static properties/methods, dynamic ones will have an advantage if > > naming matches. > > Of course, the ability to use usual prefixes will be preserved. > > > > 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. > > > > With best regards, > > MaxD > > > Hi, MaxD! > > Is there a particular problem you=E2=80=99re trying to solve with this pr= oposal? > 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 develop= ers 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 possi= ble to > unknowingly use or overwrite a class property, when that is not the inten= t. > I think this leads to a poor developer experience, so I would be against > this change. > > Cheers, > Ben > > > > --0000000000009a288305a497ce89--