Skip to content

Commit

Permalink
Fix #70
Browse files Browse the repository at this point in the history
  • Loading branch information
sorinsarca committed Aug 4, 2020
1 parent 4acc199 commit 45de0e3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ReflectionClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,30 @@ public function getCode()
}
if(isset($constants[$id_start])){
$id_start = $constants[$id_start];
} elseif($context === 'new'){
if(in_array($id_start_ci, $class_keywords)) {
if (!$inside_structure) {
$isUsingScope = true;
}
} else {
if ($classes === null) {
$classes = $this->getClasses();
}
if (isset($classes[$id_start_ci])) {
$id_start = $classes[$id_start_ci];
}
if ($id_start[0] !== '\\') {
$id_start = $nsf . '\\' . $id_start;
}
}
} elseif($context === 'use' ||
$context === 'instanceof' ||
$context === 'args' ||
$context === 'return_type' ||
$context === 'extends' ||
$context === 'root'
){
if($id_start_ci === 'self' || $id_start_ci === 'static' || $id_start_ci === 'parent'){
if(in_array($id_start_ci, $class_keywords)){
if (!$inside_structure && !$id_start_ci === 'static') {
$isUsingScope = true;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ReflectionClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ public function testNewInstance()
$this->assertEquals($e, $this->c($f));
}

public function testNewInstance2()
{
$f = function (){ new A; };
$e = 'function (){ new \Opis\Closure\Test\A; }';
$this->assertEquals($e, $this->c($f));

$f = function (){ new A\B; };
$e = 'function (){ new \Opis\Closure\Test\A\B; }';
$this->assertEquals($e, $this->c($f));

$f = function (){ new \A; };
$e = 'function (){ new \A; }';
$this->assertEquals($e, $this->c($f));

$f = function (){ new A(new B, [new C]); };
$e = 'function (){ new \Opis\Closure\Test\A(new \Opis\Closure\Test\B, [new \Opis\Closure\Test\C]); }';
$this->assertEquals($e, $this->c($f));

$f = function (){ new self; new static; new parent; };
$e = 'function (){ new self; new static; new parent; }';
$this->assertEquals($e, $this->c($f));
}

public function testInstanceOf()
{
$f = function (){ $c = null; $b = '\X\y'; v($c instanceof $b);};
Expand Down

0 comments on commit 45de0e3

Please sign in to comment.