-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Delay freeing of overwritten values in assignments #10606
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c0327c
Delay freeing of overwritten values in assignments
dstogov 47d3b6f
Add various tests for GH-10168
iluuu1994 4811078
Delay destructor for zend_assign_to_typed_ref
iluuu1994 5116ca5
Delay destructor for zend_std_write_property
dstogov 94392ec
Add GC_DTOR/GC_DTOR_NO_REF macros
iluuu1994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
--TEST-- | ||
GH-10168: Assign | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = new Test; | ||
var_dump($a = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,18 @@ | ||
--TEST-- | ||
GH-10168: Assign dim | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = [new Test]; | ||
var_dump($a[0] = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,19 @@ | ||
--TEST-- | ||
GH-10168: Assign dim ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = [new Test]; | ||
$tmp = new Test; | ||
var_dump($a[0] = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,22 @@ | ||
--TEST-- | ||
GH-10168: Assign dim ref with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = [new Test]; | ||
Test::$test = &$a[0]; | ||
$tmp = new Test; | ||
var_dump($a[0] = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,21 @@ | ||
--TEST-- | ||
GH-10168: Assign dim with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = [new Test]; | ||
Test::$test = &$a[0]; | ||
var_dump($a[0] = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,32 @@ | ||
--TEST-- | ||
GH-10168: Assign prop | ||
--FILE-- | ||
<?php | ||
|
||
class Box { | ||
public ?Test $value; | ||
} | ||
|
||
class Test { | ||
function __destruct() { | ||
global $box; | ||
$box->value = null; | ||
} | ||
} | ||
|
||
function test($box) { | ||
var_dump($box->value = new Test); | ||
} | ||
|
||
$box = new Box(); | ||
$box->value = new Test; | ||
test($box); | ||
// Second call tests the cache slot path | ||
test($box); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#3 (0) { | ||
} | ||
object(Test)#3 (0) { | ||
} |
This file contains hidden or 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,32 @@ | ||
--TEST-- | ||
GH-10168: Assign prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Box { | ||
public ?Test $value; | ||
} | ||
|
||
class Test { | ||
function __destruct() { | ||
global $box; | ||
$box->value = null; | ||
} | ||
} | ||
|
||
function test($box) { | ||
$tmp = new Test; | ||
var_dump($box->value = &$tmp); | ||
} | ||
|
||
$box = new Box(); | ||
$box->value = new Test; | ||
test($box); | ||
// Second call tests the cache slot path | ||
test($box); | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,35 @@ | ||
--TEST-- | ||
GH-10168: Assign prop ref with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Box { | ||
public ?Test $value; | ||
} | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
global $box; | ||
$box->value = null; | ||
} | ||
} | ||
|
||
function test($box) { | ||
$tmp = new Test; | ||
var_dump($box->value = &$tmp); | ||
} | ||
|
||
$box = new Box(); | ||
$box->value = new Test; | ||
Test::$test = &$box->value; | ||
test($box); | ||
// Second call tests the cache slot path | ||
test($box); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#3 (0) { | ||
} | ||
NULL |
This file contains hidden or 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,35 @@ | ||
--TEST-- | ||
GH-10168: Assign prop with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Box { | ||
public ?Test $value; | ||
} | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
global $box; | ||
$box->value = null; | ||
} | ||
} | ||
|
||
function test($box) { | ||
var_dump($box->value = new Test); | ||
} | ||
|
||
$box = new Box(); | ||
$box->value = new Test; | ||
Test::$test = &$box->value; | ||
test($box); | ||
// Second call tests the cache slot path | ||
test($box); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#3 (0) { | ||
} | ||
object(Test)#3 (0) { | ||
} |
This file contains hidden or 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,18 @@ | ||
--TEST-- | ||
GH-10168: Assign ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = new Test; | ||
$tmp = new Test; | ||
var_dump($a = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
NULL |
This file contains hidden or 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,20 @@ | ||
--TEST-- | ||
GH-10168: Assign ref with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
$GLOBALS['a'] = null; | ||
} | ||
} | ||
|
||
$a = new Test; | ||
$tmp = new Test; | ||
var_dump($a = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
NULL |
This file contains hidden or 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,20 @@ | ||
--TEST-- | ||
GH-10168: Assign static prop | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
Test::$test = null; | ||
} | ||
} | ||
|
||
Test::$test = new Test; | ||
var_dump(Test::$test = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,20 @@ | ||
--TEST-- | ||
GH-10168: Assign static prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
|
||
function __destruct() { | ||
Test::$test = null; | ||
} | ||
} | ||
|
||
Test::$test = new Test; | ||
$tmp = new Test; | ||
var_dump(Test::$test = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
NULL |
23 changes: 23 additions & 0 deletions
23
Zend/tests/gh10168/assign_static_prop_ref_with_prop_ref.phpt
This file contains hidden or 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,23 @@ | ||
--TEST-- | ||
GH-10168: Assign static prop ref with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
static ?Test $test2; | ||
|
||
function __destruct() { | ||
Test::$test = null; | ||
} | ||
} | ||
|
||
Test::$test = new Test; | ||
Test::$test2 = &Test::$test; | ||
$tmp = new Test; | ||
var_dump(Test::$test = &$tmp); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,22 @@ | ||
--TEST-- | ||
GH-10168: Assign static prop with prop ref | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static ?Test $test; | ||
static ?Test $test2; | ||
|
||
function __destruct() { | ||
Test::$test = null; | ||
} | ||
} | ||
|
||
Test::$test = new Test; | ||
Test::$test2 = &Test::$test; | ||
var_dump(Test::$test = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
This file contains hidden or 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,20 @@ | ||
--TEST-- | ||
GH-10168: Assign static prop | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
static $test; | ||
|
||
function __destruct() { | ||
Test::$test = null; | ||
} | ||
} | ||
|
||
Test::$test = new Test; | ||
var_dump(Test::$test = new Test); | ||
|
||
?> | ||
--EXPECT-- | ||
object(Test)#2 (0) { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
in each
__destruct
I would suggest to addecho "D\n";
at the start to make sure the destruction is really called at the time when expected/needed to test