> On May 1, 2020, at 09:44, Max D <m...@bukrek.net> 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=1);
> 
> This directive will switch interpreter mode, where class declared
> properties and methods are accessible as regular variables and functions at
> class code.
> 
> So, such a fragment
> 
> public function __construct() {
>   $this->get = $this->clean($_GET);
>   $this->post = $this->clean($_POST);
>   $this->request = $this->clean($_REQUEST);
>   $this->cookie = $this->clean($_COOKIE);
>   $this->files = $this->clean($_FILES);
>   $this->server = $this->clean($_SERVER);
> }
> 
> will look so with the proposed directive:
> 
> public function __construct() {
>   $get = clean($_GET);
>   $post = clean($_POST);
>   $request = clean($_REQUEST);
>   $cookie = clean($_COOKIE);
>   $files = clean($_FILES);
>   $server = clean($_SERVER);
> }
> 
> 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.
> 
> 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’re trying to solve with this proposal? You 
say, “All the years with PHP I hate writing classes. The need to prefix EVERY 
property and method use looks horrible and writes horrible.”

I’m generally in favor of changes that make it easier for developers to do 
their jobs well, but I don’t 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’s 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



Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to