Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84554 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57338 invoked from network); 11 Mar 2015 16:21:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2015 16:21:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:38119] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/B8-07702-2AB60055 for ; Wed, 11 Mar 2015 11:21:54 -0500 Received: by widex7 with SMTP id ex7so39752977wid.3 for ; Wed, 11 Mar 2015 09:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=VPOLfzwWTOzNdc7YOUQNcs6iLB7OVXPguIDodNvOwL8=; b=qdzhoLf/P3oMZseEZDRBulX3u976wioOa1tnpn9ZtbBSV+RBYwSqUMVYXrAn+n4ZuI BlncXKW9icUEgWG2x9yJWRB4xaE2OshciVH/m7m2RsK+IW5BZ8I6Gz6QnAwio+MuIVRU zLfagf/c9yfyKhzF6W4lBfp3Ih49+N+dbsCcTSjgTeLBnf4cjUaensVKwVt3eCIRfJlV VlTqURVL8dcFJwA1sOmyFubp6Dve7Z2gQt/kPFMOyb2OGMRP/V1DEX1enzN5eO5HyA4o NxHa8EwTTpZPnghMhhL+mjyXknhFxRJLZmDlL5l8qM/Sil3hPxzXDIzV5K4JBDm30Ar6 euzA== X-Received: by 10.194.110.233 with SMTP id id9mr79864922wjb.136.1426090911290; Wed, 11 Mar 2015 09:21:51 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id i10sm6050121wja.40.2015.03.11.09.21.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 09:21:50 -0700 (PDT) Message-ID: <55006B7E.1080500@gmail.com> Date: Wed, 11 Mar 2015 16:21:18 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: <24.71.03288.592FDF45@pb1.pair.com> <54FE20E5.1060605@gmail.com> <55003D12.5010006@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Request Feedback for Instance Variable Sugar RFC From: rowan.collins@gmail.com (Rowan Collins) Johannes Ott wrote on 11/03/2015 13:36: > Am 11.03.2015 um 14:03 schrieb Rowan Collins: >> Johannes Ott wrote on 10/03/2015 20:46: >>> okay indeed the dynamic properties are a problem I didn't think about on >>> my suggestion. Without the wish to hijack this thread for another >>> typesafety discussion, I must say again that PHP needs a less dynamic >>> and more declaratively properties concept in my opinion. >> Yes, I think a standard way to say that a particular object has strictly >> declared all its properties, and should not allow would be useful. >> >> (Even with that, though, I'd be against guessing that "$foo" meant >> "$this->foo"; it just makes code harder to read.) >> > I disagree, programming Java beside PHP since about 15 years now, > personally I think always having "this"-keyword, where it is not > necassary in a strict OOP-world, makes the code more unreadable for the > simple fact it is more to read. My reasoning is that code that is ambiguous is hard to read. If "$foo" can mean either "a local variable called $foo" or "a property of the current object called $foo", then you have to know which it is in order to understand what code is doing. This is not about "a strict OOP-world", incidentally, it's about scoping rules. Java imports object properties into the scope of each method, PHP does not. Even if properties had to be declared (which is probably a good idea), local variables still wouldn't be - in Java, the fact that it's not declared locally means it *must* be coming from somewhere else. I also know that when I was first learning Java at school, it confused me immensely which variables I was allowed to access in static contexts. In PHP, that's simple - if you can't access $this, you can't access any of it's properties. >>> So I would suggest for now to keep the $this variable, but to make it >>> more similar to other OOP-languages I would suggest to remove the >>> $-character in front. In my opinion it would fit better to other object >>> keywords like parent and self as well. >> Other OOP languages only don't have a sigil such as $ in front of this >> if they don't have one in front of *any* variable. Why should $this, >> which acts like a normal variable in pretty much every way, drop the $ >> when every other variable in the language has one? >> >> Note that the syntax of parent and self is different, and is consistent >> with static member/method access, or more strictly "scope resolution". >> You can't pass parent or self around as variables, only use them to >> resolve scopes, so they don't have a $. >> > I only agree a bit, because the keyword "this", is what to call a > hybridization, more often used to define the scope of the property or > method you want to use, then used really as a pure variable. > > For example: > > this->a; > or > this->some_function(...); > > just defining the scope as in the current instance is much more used then. > > some_function($this); This is true of any object variable. These resolve the scope of the property/method to the variable $foo: $a = $foo->a; $foo->some_function(...); These resolve the scope of the property/method to the variable $this: $a = $this->a; $this->some_function(...); If you want to resolve the scope of a method to the current object without using the variable $this, you can also use the "static" keyword; these are equivalent: $this->some_function(...); static::some_function(...); // http://3v4l.org/E0XYs There is nothing unvariable-like about $this, so if variables begin with $, $this should begin with $. Regards, -- Rowan Collins [IMSoP]