-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix inconsistent $this behavior #1918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1889,6 +1884,15 @@ PHP_FUNCTION(extract) | |||
|
|||
if (Z_TYPE(final_name) == IS_STRING && php_valid_var_name(Z_STRVAL(final_name), Z_STRLEN(final_name))) { | |||
zval *orig_var; | |||
|
|||
if (Z_STRLEN(final_name) == sizeof("this")-1 && !strcmp(Z_STRVAL(final_name), "this")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use zend_string_equals(Z_STR(final_name), CG(known_string)[THIS_STR[)
* master: Fixed bug #72213 (Finally leaks on nested exceptions). Forbid dynamic calls to scope introspection functions Allow empty property names Ensure no entry predecessors for SSA construction Replace BB end with BB len Fixed white-spaces
From a quick scan, it looks like handling for by-reference fetches of |
@nikic it's possible to pass or assign $this by reference, but this assignment is actually done by value and changes to reference won't affect value of $this. |
@dstogov Yeah, I did understand that. What I'm referring to is that reference assignment usually suppresses the "undefined variable" notice, but in this case it would still be there, right? Though probably this doesn't matter anyway. |
ah, right. I'll think about this. From: Nikita Popov notifications@github.com @dstogovhttps://github.com/dstogov Yeah, I did understand that. What I'm referring to is that reference assignment usually suppresses the "undefined variable" notice, but in this case it would still be there, right? Though probably this doesn't matter anyway. You are receiving this because you were mentioned. |
@dstogov Tangentially related, as it would solve the issue with references as well: Shouldn't any access to |
* master: (45 commits) Re-Fixed bug #72155 (use-after-free caused by get_zval_xmlrpc_type) Revert "fix #72155 (use-after-free caused by get_zval_xmlrpc_type)" Split ZEND_SEND_VAR_NO_REF into ZEND_SEND_VAR_NO_REF and ZEND_SEND_VAR_NO_REF_EX (similar to ZEND_SEND_VAL) and remove ZEND_ARG_* flags. Initialize only the necessary fields. fix condition update NEWS Fixed bug #72284 (phpdbg fatal errors with coverage) fix test title Add test for bug #72258 update UPGRADING Expose missing flags from libzip at least >= 0.11.x update UPGRADING Expose missing flags from libzip at least >= 0.11.x fix #72155 (use-after-free caused by get_zval_xmlrpc_type) This is exported at implementation site, but no forward declaration can cause compile warnings Fix bug #71604 Forbid "yield from" in force closed generators Added NEWS Entry Test for bug #72221, segfault in zend_memnstr_ex Fix bug #72221 (segfault, past-the-end access) ...
…is when not in object context".
@nikic, good point. I followed your suggestion and changed RFC and implementation accordingly. Now we will get "Using $this when not in object context" exception everywhere. |
<?php
error_reporting(E_ALL);
class Foo {
function __construct() {
$this->bar($this);
var_dump($this);
}
public function bar(&$that) {
$that = "Bar";
}
}
$q = new Foo(); master
dstogov/this_var
Works. |
Right. This case is covered by corresponding RFC section https://wiki.php.net/rfc/this_var#disable_ability_to_re-assign_this_indirectly_through_reference From: Matthias Lisin notifications@github.com |
Should it also emit a warning/notice in this case? |
} else { | ||
ssa_var_info[i].type = MAY_BE_UNDEF | MAY_BE_RCN; | ||
} | ||
ssa_var_info[i].type = MAY_BE_UNDEF | MAY_BE_RCN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should add inference for the new FETCH_THIS
opcodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
This RFC targets 7.1 although introduces mutliple BC breaks. It seems like a violation of PHP's own release process:
|
* master: (134 commits) These bugs are also in 7.1-alpha Fixed(attempt to) bug #72405 (mb_ereg_replace - mbc_to_code (oniguruma) - oob read access) Maybe fix bug #72011 Fix #50845: exif_process_IFD_TAG: Use the right offset if reading from stream Improve the signature Unused var C89 compatibility Fix bug #72138 - Integer Overflow in Length of String-typed ZVAL Only allow single comma in tail Fixed bug #72399 (Use-After-Free in MBString (search_re)) Implemented FR #72385 (Update SQLite bundle lib(3.13.0)) Cleanup Add support for "instanceof" pi nodes Use union for pi constraints Cleanup Fixed bug #72395 (list() regression) Switch zend_print_zval_r to use smart_str fix test portability Fixed bug #72306 (Heap overflow through proc_open and $env parameter) update NEWS ...
It throws exception if not in object context. Removed useless opcode handlers.
USE_OPLINE | ||
zval *result = EX_VAR(opline->result.var); | ||
|
||
ZVAL_BOOL(EX_VAR(opline->result.var), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use result
(or the result
variable can be dropped instead).
* master: Updated to version 2016.5 (2016e) Updated to version 2016.5 (2016e) Updated to version 2016.5 (2016e)
* master: Fix type inference bugs Added specialized handlers for SEND_VAR/SEND_VAR_EX opcodes. Fixed mistakes in type inference rules. Fixed expected test outcome due to rule changes
Merged into master. |
No description provided.