rfc:this_var

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:this_var [2016/05/24 07:12] – Updated "Disable using $this as static variable" section dmitryrfc:this_var [2016/06/16 05:52] dmitry
Line 3: Line 3:
   * Date: 2016-05-23   * Date: 2016-05-23
   * Author: Dmitry Stogov, dmitry@zend.com   * Author: Dmitry Stogov, dmitry@zend.com
-  * Status: Under Discussion+  * Status: Accepted
   * First Published at: https://wiki.php.net/rfc/this_var   * First Published at: https://wiki.php.net/rfc/this_var
  
Line 129: Line 129:
 ==== get_defined_vars() always doesn't show value of variable $this ==== ==== get_defined_vars() always doesn't show value of variable $this ====
  
-In PHP 7.0 and below get_defined_vars() might show or not show value of $this depending on some condition. (e.g. it was shownm if we used $this variable itself). In PHP 7.1 we won't show the value of $this in all cases.+In PHP 7.0 and below get_defined_vars() might show or not show value of $this depending on some condition. (e.g. it was shown if we used $this variable itself, but not if it was used in a $this property reference or method call). In PHP 7.1 we won't show the value of $this in all cases.
  
 ==== Always show true $this value in magic method __call() ==== ==== Always show true $this value in magic method __call() ====
Line 147: Line 147:
 $x = new C; $x = new C;
 $x->foo(); $x->foo();
 +</code>
 +
 +==== Using $this when not in object context ====
 +
 +Attempt to use $this in plain function or method now will lead to exception "Using $this when not in object context". This unifies behavior with method call and property access. Previously PHP emitted "undefined variable" notice and continued execution assuming $this is NULL. It's still possible to use isset($this) and empty($this) to check object context.
 +
 +<code php>
 +function foo() {
 +    var_dump($this); // throws "Using $this when not in object context"
 +                     // php-7.0 emitted "Undefined variable: this" and printed NULL
 +}
 +foo();
 </code> </code>
  
Line 170: Line 182:
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 The vote is a straight Yes/No vote, that requires a 2/3 majority. The vote is a straight Yes/No vote, that requires a 2/3 majority.
-The voting will begin on Jun 6 and will close on Jun 16.+The voting began on Jun 6 and will close on Jun 16. 
 +<doodle title="Fix inconsistent behavior of $this variable?" auth="dmitry" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 178: Line 194:
 After the project is implemented, this section should contain  After the project is implemented, this section should contain 
   - the version(s) it was merged to   - the version(s) it was merged to
-  - a link to the git commit(s)+  - a link to the git commit [[ http://git.php.net/?p=php-src.git;a=commitdiff;h=a9512af8109e889eb2c6042c57797184930667cd|a9512af8109e889eb2c6042c57797184930667cd]]
   - a link to the PHP manual entry for the feature   - a link to the PHP manual entry for the feature
- 
-===== Rejected Features ===== 
-Keep this updated with features that were discussed on the mail lists. 
rfc/this_var.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1