-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the emission of the undefined variable notice before the array separation.
- Loading branch information
Showing
3 changed files
with
77 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
Bug #79599 (coredump in set_error_handler) | ||
--FILE-- | ||
<?php | ||
set_error_handler(function($code, $message){ | ||
throw new \Exception($message); | ||
}); | ||
function test1(){ | ||
$a[] = $b; | ||
} | ||
function test2(){ | ||
$a[$c] = $b; | ||
} | ||
try{ | ||
test1(); | ||
}catch(\Exception $e){ | ||
var_dump($e->getMessage()); | ||
} | ||
try{ | ||
test2(); | ||
}catch(\Exception $e){ | ||
var_dump($e->getMessage()); | ||
} | ||
?> | ||
--EXPECT-- | ||
string(21) "Undefined variable: b" | ||
string(21) "Undefined variable: b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5795dfd
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.
I dont’ think this fix is complete,
and actually this was the first way I thought too, but this could not fix situation likes:
5795dfd
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.
@laruence Yes, I'm aware of this issue. There are many problems with notices being thrown during write operations. I've recently fixed some of them, but it's really hard to make code safe against it and I think the approach does not scale. We discussed this with @bwoebi yesterday, and he suggested that we should introduce a deferred notice mechanism, so that notices will only be thrown after the opcode. This may have slightly different behavior when it comes to side-effects, but it would avoid most of these dangerous situations. This is something we may want to try in master.
5795dfd
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.
Always deep duplicating the symbol table should fix this kind of problems at all, but you reverted it... :<
5795dfd
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.
@laruence Duplicating the symbol table only removes one vector for accessing the variable. Unfortunately there are many others, such as $GLOBALS and references.
5795dfd
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.
I mean kind of problems means “the exception’s trace issue”, others are not the same..
anyway, please take care of the case I pasted above, since it should be broken now. thanks
5795dfd
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.
@laruence I understand, but I don't see a reason why we should address the backtrace issue without addressing the more general issue. Your patch fixed the problem for
But did not fix the problem for the nearly identical case of:
A partial fix is of course also good, but in this case the partial fix caused huge performance regressions.
The only case that's really important to handle is the
throw new Exception
one, because this is a very common pattern. This case needs to work for sure (and does work). For other cases, I would like to have a general solution with reasonable performance impact.