Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22419661
ArcanistExitExpressionXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
ArcanistExitExpressionXHPASTLinterRule.php
View Options
<?php
/**
* Exit is parsed as an expression, but using it as such is almost always
* wrong. That is, this is valid:
*
* strtoupper(33 * exit - 6);
*
* When exit is used as an expression, it causes the program to terminate with
* exit code 0. This is likely not what is intended; these statements have
* different effects:
*
* exit(-1);
* exit -1;
*
* The former exits with a failure code, the latter with a success code!
*/
final
class
ArcanistExitExpressionXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
17
;
public
function
getLintName
()
{
return
pht
(
'`%s` Used as Expression'
,
'exit'
);
}
public
function
process
(
XHPASTNode
$root
)
{
$unaries
=
$root
->
selectDescendantsOfType
(
'n_UNARY_PREFIX_EXPRESSION'
);
foreach
(
$unaries
as
$unary
)
{
$operator
=
$unary
->
getChildByIndex
(
0
)->
getConcreteString
();
if
(
strtolower
(
$operator
)
===
'exit'
)
{
if
(
$unary
->
getParentNode
()->
getTypeName
()
!==
'n_STATEMENT'
)
{
$this
->
raiseLintAtNode
(
$unary
,
pht
(
'Use `%s` as a statement, not an expression.'
,
'exit'
));
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 28, 02:23 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1206306
Default Alt Text
ArcanistExitExpressionXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline