-
Notifications
You must be signed in to change notification settings - Fork 7.9k
RFC: Turn clone()
into a function
#18919
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
Open
TimWolla
wants to merge
11
commits into
php:master
Choose a base branch
from
TimWolla:clone-function
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
212f923
zend_string: Add ZEND_STR_CLONE to known strings
TimWolla 71df8dd
zend_vm: Change error when cloning non-objects to TypeError and align…
TimWolla 24c0ce7
zend_builtin_functions: Add `clone()` as function
TimWolla c043b5e
zend_language_parser: Compile `clone` as a function call
TimWolla e1729f8
zend_ast: Remove now-unused `ZEND_AST_CLONE` AST type
TimWolla 573cd16
zend_language_parser: Support first-class-callable syntax for `clone()`
TimWolla 5457a23
zend_compile: Optimize the `clone()` function into the `ZEND_CLONE` O…
TimWolla f3462cc
opcache: Use fully-qualified function names in func_info.phpt
TimWolla 8b25a9b
Optimizer: Mark `clone()` as RC1
TimWolla 0acfc73
Add note to `clone()` / `ZEND_CLONE` that implementations need to be …
TimWolla e2bd32c
Zend: Remove dead code from clone tests
TimWolla 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
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
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,31 @@ | ||
--TEST-- | ||
Ast Printing | ||
--FILE-- | ||
<?php | ||
|
||
$x = new stdClass(); | ||
|
||
|
||
try { | ||
assert(false && $y = clone $x); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
assert(false && $y = clone($x)); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
assert(false && $y = clone(...)); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
assert(false && ($y = \clone($x))) | ||
assert(false && ($y = \clone($x))) | ||
assert(false && ($y = \clone(...))) |
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
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
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
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
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
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,55 @@ | ||
--TEST-- | ||
Clone as a function. | ||
--FILE-- | ||
<?php | ||
|
||
$x = new stdClass(); | ||
|
||
\var_dump(\clone($x)); | ||
\var_dump(\array_map('clone', [$x, $x, $x])); | ||
\var_dump(\array_map(clone(...), [$x, $x, $x])); | ||
|
||
class Foo { | ||
private function __clone() { | ||
|
||
} | ||
|
||
public function clone_me() { | ||
// Verify visibility when going through array_map(). | ||
return array_map(\clone(...), [$this]); | ||
} | ||
} | ||
|
||
$f = new Foo(); | ||
|
||
$clone = $f->clone_me()[0]; | ||
|
||
var_dump($f !== $clone); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(stdClass)#%d (0) { | ||
} | ||
array(3) { | ||
[0]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
[1]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
[2]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
} | ||
array(3) { | ||
[0]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
[1]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
[2]=> | ||
object(stdClass)#%d (0) { | ||
} | ||
} | ||
bool(true) |
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
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.
Uh oh!
There was an error while loading. Please reload this page.