-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simulate
offsetSet
to get throw points for ArrayAccess assignment
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 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
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,80 @@ | ||
<?php | ||
|
||
namespace Bug4852; | ||
|
||
use ArrayAccess; | ||
use Exception; | ||
|
||
final class DefinitelyThrows implements ArrayAccess | ||
{ | ||
public function offsetExists ($offset) {} | ||
public function offsetGet ($offset) {} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function offsetSet ($offset , $value) { | ||
throw new Exception(); | ||
} | ||
public function offsetUnset ($offset) {} | ||
} | ||
|
||
final class MaybeThrows1 implements ArrayAccess | ||
{ | ||
public function offsetExists ($offset) {} | ||
public function offsetGet ($offset) {} | ||
public function offsetSet ($offset , $value) { | ||
throw new Exception(); | ||
} | ||
public function offsetUnset ($offset) {} | ||
} | ||
|
||
class MaybeThrows2 {} | ||
|
||
final class DefinitelyNoThrows implements ArrayAccess | ||
{ | ||
public function offsetExists ($offset) {} | ||
public function offsetGet ($offset) {} | ||
|
||
/** | ||
* @throws void | ||
*/ | ||
public function offsetSet ($offset , $value) {} | ||
public function offsetUnset ($offset) {} | ||
} | ||
|
||
$foo = new DefinitelyThrows(); | ||
try { | ||
$foo[] = 'value'; | ||
} catch (Exception $e) { | ||
// not dead | ||
} | ||
|
||
$bar = new MaybeThrows1(); | ||
try { | ||
$bar[] = 'value'; | ||
} catch (Exception $e) { | ||
// not dead | ||
} | ||
|
||
$buz = new MaybeThrows2(); | ||
try { | ||
$buz[] = 'value'; | ||
} catch (Exception $e) { | ||
// not dead | ||
} | ||
|
||
$baz = new DefinitelyNoThrows(); | ||
try { | ||
$baz[] = 'value'; | ||
} catch (Exception $e) { | ||
// dead | ||
} | ||
|
||
$array = []; | ||
try { | ||
$array[] = 'value'; | ||
} catch (Exception $e) { | ||
// dead | ||
} | ||
|