forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug #70630 (Closure::call/bind() crash with ReflectionFunction-…
…>getClosure()) This additionally removes support for binding to an unknown (not in parent hierarchy) scope. Removing support for cross-scope is necessary for certain compile-time assumptions (like class constants) to prevent unexpected results
- Loading branch information
Showing
6 changed files
with
124 additions
and
16 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
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,24 @@ | ||
--TEST-- | ||
Bug #70630 (Closure::call/bind() crash with ReflectionFunction->getClosure()) | ||
--FILE-- | ||
<?php | ||
|
||
class a {} | ||
function foo() {} | ||
|
||
foreach (["substr", "foo"] as $fn) { | ||
$x = (new ReflectionFunction($fn))->getClosure(); | ||
$x->call(new a); | ||
Closure::bind($x, new a, "a"); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
|
||
Warning: Cannot bind function substr to an object in %s on line %d | ||
|
||
Warning: Cannot bind function substr to an object in %s on line %d | ||
|
||
Warning: Cannot bind function foo to an object in %s on line %d | ||
|
||
Warning: Cannot bind function foo to an object in %s on line %d |
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,64 @@ | ||
--TEST-- | ||
Closure::call() or Closure::bind() to independent class must fail | ||
--FILE-- | ||
<?php | ||
|
||
class foo { | ||
public $var; | ||
|
||
function initClass() { | ||
$this->var = __CLASS__; | ||
} | ||
} | ||
|
||
class bar { | ||
public $var; | ||
|
||
function initClass() { | ||
$this->var = __CLASS__; | ||
} | ||
|
||
function getVar() { | ||
assert($this->var !== null); // ensure initClass was called | ||
return $this->var; | ||
} | ||
} | ||
|
||
class baz extends bar { | ||
public $var; | ||
|
||
function initClass() { | ||
$this->var = __CLASS__; | ||
} | ||
} | ||
|
||
function callMethodOn($class, $method, $object) { | ||
$closure = (new ReflectionMethod($class, $method))->getClosure((new ReflectionClass($class))->newInstanceWithoutConstructor()); | ||
$closure = $closure->bindTo($object, $class); | ||
return $closure(); | ||
} | ||
|
||
$baz = new baz; | ||
|
||
callMethodOn("baz", "initClass", $baz); | ||
var_dump($baz->getVar()); | ||
|
||
callMethodOn("bar", "initClass", $baz); | ||
var_dump($baz->getVar()); | ||
|
||
callMethodOn("foo", "initClass", $baz); | ||
var_dump($baz->getVar()); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(3) "baz" | ||
string(3) "bar" | ||
|
||
Warning: Cannot bind function foo::initClass to object of class baz in %s on line %d | ||
|
||
Fatal error: Uncaught Error: Using $this when not in object context in %s:%d | ||
Stack trace: | ||
#0 %s(%d): initClass() | ||
#1 %s(%d): callMethodOn('foo', 'initClass', Object(baz)) | ||
#2 {main} | ||
thrown in %s on line %d |
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
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
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